https://github.com/cotag/em-promise
A promise/deferred implementation for EventMachine
https://github.com/cotag/em-promise
Last synced: about 1 year ago
JSON representation
A promise/deferred implementation for EventMachine
- Host: GitHub
- URL: https://github.com/cotag/em-promise
- Owner: cotag
- License: mit
- Created: 2012-10-20T01:18:25.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-03-21T00:27:57.000Z (over 13 years ago)
- Last Synced: 2025-04-11T22:12:37.379Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 163 KB
- Stars: 21
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE
Awesome Lists containing this project
README
h1. EM-Promise
!https://secure.travis-ci.org/cotag/em-promise.png(Build Status)!:https://travis-ci.org/cotag/em-promise
A promise / deferred implementation for EventMachine inspired by "AngularJS":http://docs.angularjs.org/api/ng.$q / "Kris Kowal's Q.":https://github.com/kriskowal/q
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
h2. Start using it now
# Read the "Documentation":http://rubydoc.info/gems/em-promise/EventMachine/Q
# Then @gem install em-promise@