Celluloid 0.7.0: Actors for Ruby, now with timers, FSMs, and a celluloid-io gem

I figured I’d get one more release of Celluloid out before the end of
the year :slight_smile: And hey, ruby-talk could use some mail that isn’t spam.

Celluloidprovides a simple and natural way to build fault-tolerant
concurrent programs in Ruby. WithCelluloid, you can build systems out
of concurrent objects just as easily as you build sequential programs
out of regular objects. Recommended for any developer, including
novices,Celluloidshould help ease your worries about building
multithreaded Ruby programs.

Celluloidwraps objects in threads, allowing them to run concurrently,
while still letting you talk to them using standard Ruby method call
conventions. It also enables asynchronous method calls which tell a
method to do something in the background, and futures, which let you
request a method be executed then check back later for the result.

The biggest change in Celluloid 0.7.0 is the splitting out of the
Celluloid::IO subsystem into a separate gem, which is now available
here:

Why a separate gem? While Celluloid::IO presently uses Kernel.select
for monitoring IO objects, the next release will use the high
performance nio4r API. However, nio4r has a native dependency on all
platforms except JRuby, so I thought it would be nice to let people
play with celluloid without having to install nio4r.

Celluloid::IO provides a complete evented IO subsystem, but with all
calls wrapped in fibers, exposing a synchronous API. The goal of the
next release of Celluloid::IO is to include duck types for the most
popular Ruby IO classes like TCPSocket and UDPSocket, allowing
existing libraries written using these classes and blocking I/O to run
top of Celluloid::IO’s evented subsystem with almost no modification.

Celluloid 0.7.0 also brings with it a complete timer subsystem for
concurrent objects. Celluloid#sleep now defers to an actor’s
scheduler, allowing it to continue to respond to messages while an
actor is sleeping. Celluloid#after allows you to schedule a block for
execution later.

Finally, the experimental Celluloid::FSM module allows you to build
timer-driven FSMs out of concurrent objects. These FSMs can
automatically move to a new state after a delay unless another state
change occurs, providing a great way to implement timeouts and
retries. FSMs are a rock-solid way to build fully asynchronous systems
that continue to operate in hostile environments. The API is presently
experimental and may get split out into a new gem in the future.
Celluloid::FSM is inspired by Erlang’s gen_fsm.

Enjoy!

Full changelog:

  • Celluloid::Task abstraction replaces Celluloid::Fiber
  • Celluloid#tasks API to introspect on running tasks
  • Move Celluloid::IO into its own gem, celluloid-io
  • Finite state machines with Celluloid::FSM
  • Fix bugs in supervisors handling actors that crash during initialize
  • Old syntax Celluloid::Future() { … } deprecated. Please use the
    #future
    method or Celluloid::Future.new { … } to create futures
  • New timer subsystem! Bullet point-by-bullet point details below
  • Celluloid#after registers a callback to fire after a given time
    interval
  • Celluloid.sleep and Celluloid#sleep let an actor continue processing
    messages
  • Celluloid.receive and Celluloid#receive now accept an optional timeout
  • Celluloid::Mailbox#receive now accepts an optional timeout