38. Synchronous
Asynchronicity
Write code that looks like
puts "Setting up HTTP request #1"
data = async_fetch('http://www.google.com/')
puts "Fetched page #1: #{data.response_header.status}"
*Example from http://www.igvita.com/2009/05/13/fibers-cooperative-scheduling-in-ruby/
39. Synchronous
Asynchronicity
Write code that looks like
puts "Setting up HTTP request #1"
data = async_fetch('http://www.google.com/')
puts "Fetched page #1: #{data.response_header.status}"
Looks synchronous. Acts asynchronous.
*Example from http://www.igvita.com/2009/05/13/fibers-cooperative-scheduling-in-ruby/
45. What Is Event-Driven
Programming?
• Age-old Technique
• Familiar to UI & Kernel Developers
46. What Is Event-Driven
Programming?
• Age-old Technique
• Familiar to UI & Kernel Developers
• Control Flow determined by Events
47. What Is Event-Driven
Programming?
• Age-old Technique
• Familiar to UI & Kernel Developers
• Control Flow determined by Events
• Callbacks the central construct
48. EventMachine Example
class Echo < EventMachine::Connection
def post_init
send_data 'Hello'
end
def receive_data(data)
p data
end
end
EventMachine.run {
EventMachine.connect '127.0.0.1', 8081, Echo
}