From: Tony Arcieri Date: 2008-02-13T10:48:07+09:00 Subject: Re: Rev/actor TCP monkey patching ------=_Part_2891_12936872.1202867294318 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 12, 2008 6:10 PM, fedzor 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 ------=_Part_2891_12936872.1202867294318--