No commit activity in last 3 years
No release in over 3 years
Celluloid based multi-threaded promise implementation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Celluloid Promise

Build Status

A promise / deferred implementation for Celluloid 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 'celluloid-promise'

def asyncGreet(name)
	deferred = Celluloid::Q.defer
	
	Thread.new do
		sleep 10
		deferred.resolve("Hello #{name}")
	end
	
	deferred.promise
end


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


As that example is pretty terrible here is a decent write up on the uses for promises

Start using it now

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

Use case

Celluloid provides a toolkit for building concurrent applications however coordinating complex chains of concurrent events can be difficult.
Celluloid-Promise provides the following:

  • allows you to track a mash up of events across Actors
  • guarantees serial execution of callbacks
  • callback chains are spread across multiple threads
    • So multiple promise chains can be executed concurrently

Of course passing blocks around is a fairly dangerous exercise, so do the following and you’ll be safe

  • use Celluloid-Promise for flow control
  • resolve and reject promises with locally scoped variables
  • call Actor methods to change state or instance variables