Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

celluloid-promise

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

celluloid-promise

  • 1.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

h1. Celluloid Promise

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

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


h2. Start using it now

Read the "Documentation":http://rubydoc.info/gems/celluloid-promise/Celluloid/Promise

Then @gem install celluloid-promise@

h2. 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":https://github.com/celluloid/celluloid/wiki/Blocks#proposal-for-fixing-blocks, 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 class variables

FAQs

Package last updated on 20 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc