snacktime wrote:
> Ok I grabbed the source from the svn repo and am looking through it.
> Looks like there are enough samples and code there to get an idea of
> how it all works.
Sounds like you figured it out. You get the defertothread-like behavior
with EventMachine#defer and there is a code sample in the Rdoc. Very
simple.
The Deferrable pattern is a separate feature that doesn't require thread
pools to work. Deferrable is illustrated with the TcpConnectTester in
the protocols directory, and it's also very simple although there isn't
much documentation of the pattern yet.
The idea here is identical to Twisted's Deferred object. You start with
an ordinary class of your own, like a network-protocol handler, that is
written to receive normal EventMachine events. Include
EventMachine:

eferrable in your class and then instantiate your objects
as you normally would. The Deferrable module adds several methods to
your class: #callback, #errback, and #set_deferred_status(status,
*args). As long as your object exists in memory, your program can add
code blocks to it via one or more calls to callback and errback, and set
the object's "status" (notionally, the outcome of the deferred operation
that it performs) via #set_deferred_status. If the status is :succeeded,
then all of the code blocks added via #callback are automatically called
in order with the arguments passed to #set_deferred_status. If status is
:failed, the #errback chain is called. As with Twisted, you can call
#callback and #errback even after the operation status is known.
But in your OP, you didn't say anything about needing Deferrables or
locally-blocking operations. Sounds like you're trying to do a
plain-vanilla multi-platform network server. If you need the newer
stuff, let me know and I'll publish a new release and add some more
docs.
The big problem that Windows users have with EM is that it's a compiled
extension. Let me know if you have trouble with it. I just made a win32
binary gem the other day for EM version 0.7.0. I'd like to release a
pure-Ruby version of EM someday soon, although there are currently two
problems with it: it's about half as fast as the extension (although
that is probably plenty fast enough for most applications), and it
requires a recent snap of Ruby 1.8.5 to get needed improvements to
nonblocking I/O.
--
Posted via
http://www.ruby-forum.com/.