Tony Arcieri
2/13/2008 1:48:00 AM
[Note: parts of this message were removed to make it a legal post.]
On Feb 12, 2008 6:10 PM, fedzor <fedzor@gmail.com> wrote:
> Here is where I've found a problemo will occur. In my *ahem*
> extensive *ahem* research with your fine fine actors ;-), concurrency
> only exists when run within an actor - Actor.current has failed me
> here! Example:
>
> foods = ['chocolate', 'seltzer', 'awesome sauce']
> foods.each do |food|
>
> Actor.spawn(food) do |f|
> sleep 1
> puts f
> end
> end
> puts "foods rounded up"
>
I should really document this better, but: In Revactor, Actors are
Fiber-based, so anything that blocks for prolonged periods of time will hang
all Actors in the system. It's the same sort of thing you'll encounter with
an evented framework like EventMachine.
Fortunately, there's "Actor-safe" replacements for most of the blocking
tasks you'll perform in a networked application, namely: DNS resolution,
opening connections, SSL handshakes, and reading from and writing to the
network.
In the case of sleep, there's the handy:
Actor.sleep 1
Which is just shorthand for Actor.receive { |filter| filter.after 1 }
For anything related to networking, you need to use Actor::TCP or
Actor::HttpClient (which uses the fully asynchronous HTTP client from Rev)
To execute long-running blocks of code which aren't related to networking,
the next release of Revactor will be thread safe. This means you can spin
the long running task off in a thread, and have it send a message when it
completes.
--
Tony Arcieri
ClickCaster, Inc.
tony@clickcaster.com