Skip to content

cotag/em-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A promise/deferred implementation for EventMachine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages