EM::Deferrable and EM.defer
Clone this wiki locally
Be careful not to mix up EM::Deferrable and EM.defer:
- EM::Deferrable is a module which can be mixed into classes whose instances then respond to #callback and #errback to store callback actions. The stored callbacks are then triggered by calling #succeed resp. #fail on the instances. EM::DefaultDeferrable is the class cousin of EM::Deferrable. See https://github.com/eventmachine/eventmachine/blob/master/lib/em/deferrable.rb for further instructions.
- EM.defer is used to push a otherwise blocking operation on an EM internal queue whose jobs are then processed by a thread pool of 20 threads (by default). You can use EM.defer with operations which aren’t made to work asynchronously. See https://github.com/eventmachine/eventmachine/blob/master/lib/eventmachine.rb#L993 for more information.
EM.defer is one of EventMachine’s mechanisms for lightweight concurrency. (Spawned Processes is another.)
EM.defer makes it easy and graceful to initiate a long-running (“deferrable”) operation (such as a call to an external web site), and attach any number of code blocks to be executed when the deferrable operation completes.
This page is under construction. The intention is that this page will become the primary resource for learning about Deferrable.