Project

em-promise

0.01
No commit activity in last 3 years
No release in over 3 years
EventMachine based, promise/deferred implementation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 1.0.0.beta.4
 Project Readme

EM-Promise

Build Status

A promise / deferred implementation for EventMachine inspired by AngularJS / Kris Kowal’s 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

Start using it now

  1. Read the Documentation
  2. Then gem install em-promise