From: Tony Arcieri Date: 2008-02-13T10:57:32+09:00 Subject: Re: Rev/actor TCP monkey patching ------=_Part_2914_18055402.1202867860067 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 12, 2008 6:39 PM, fedzor wrote: > > As a follow up, I realized why it wasn't working: bug in filters. I'm > too scared to patch it up, but I think I'll do that anyways. Example > problem: > > myactor = Actor.spawn do > Actor.receive do |filter| > filter.when(:dog) { puts "I got a dog!" } > end > end > > myactor << :dog > > Run it and see..... NOTHING. it exits.... so..... what up G. > The problem here is that you need to do something which yields control back to the Actor scheduler before it can run. The simplest thing you can do is: Actor.sleep 0 This will yield control to the scheduler, which will process any outstanding messages then return control back to you (since you told it you wanted to sleep for 0 seconds) It's pretty confusing from irb, I'll admit... When doing anything with Actors, just remember you're "queuing up" operations which will run later... later being whenever you call Actor.receive. Actor.receive is the only way to defer control to other Actors (keeping in mind Actor.sleep is just shorthand for Actor.receive) All of the "blocking" operations in Revactor, things like Actor::TCP.connect, Actor::HttpClient.get, etc. are all calling Actor.receive underneath. -- Tony Arcieri ClickCaster, Inc. tony@clickcaster.com ------=_Part_2914_18055402.1202867860067--