From the perspective of dealing with error handling, deferred and promise apis are to asynchronous programing what try, catch and throw keywords are to synchronous programming.
require 'rubygems'
require 'em-promise'
def asyncGreet(name)
deferred = EM::Q.defer
EM::Timer.new(5) do
EM.defer do
deferred.resolve("Hello #{name}")
end
end
deferred.promise
end
EventMachine.run do
asyncGreet('Robin Hood').then(proc { |greeting|
p "Success: #{greeting}"
}, proc { |reason|
p "Failed: #{reason}"
})
asyncGreet('The Dude').then do |greeting|
p "Jeff '#{greeting}' Lebowski"
end
end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4