Sha256: 16f39025f66624d95862295a825c0d2a2d621e17730a558a92053e57065db1df

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

h1. EM-Promise

!https://secure.travis-ci.org/cotag/em-promise.png!

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.

<pre><code class="ruby">
require 'rubygems'
require 'eventmachine'
require 'em-promise'

def asyncGreet(name)
	deferred = EM::Defer.new
	
	EM::Timer.new(5) do
		EM.defer do
			deferred.resolve("Hello #{name}")
		end
	end
	
	deferred.promise
end


EventMachine.run do

	promise = asyncGreet('Robin Hood')
	promise.then(proc { |greeting|
		p "Success: #{greeting}"
	}, proc { |reason|
		p "Failed: #{reason}"
	})
	
end

</code></pre>


h2. Start using it now

@gem install em-promise@

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-promise-1.0.3 README.textile