Guillaume Dorchies
2008-Nov-21 08:22 UTC
[Eventmachine-talk] How can I create synchrone messaging system
Hello I try to do something like that sp=EM.spawn do ..... send_message(message) answer=pause .... send_message(message) answer=pause .... end module ServerComm def data_receive(data) message=F(data) sp=Q(message) sp.notify(message) end end In my server I can have many spawn process. In Q function I use a uuid to find or to create a spawned process send_message send over the network and after I want to wait a answer. I don''t known how to write the pause function. Where I can find the right documentation ? regards,guillaume -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20081121/fba58c10/attachment.html>
Roger Pack
2008-Nov-21 15:46 UTC
[Eventmachine-talk] How can I create synchrone messaging system
unfortunately with EM style stuff, instead of send_message(message) answer=pause # receive message send_message(message2) you have to split it up, like def receive_data m if current_state == :got_first_message send_message_1 else send_message_2 end end if you don''t want to do that [and want to use pause], then I''d say just use a threaded socket approach [with select for the pauses]. Or you could use revactor, which is a different library and uses somewhat of a hybrid using Evented architecture, too. -=R On Fri, Nov 21, 2008 at 9:22 AM, Guillaume Dorchies <guillaume.dorchies at gmail.com> wrote:> Hello > > I try to do something like that > > sp=EM.spawn do > ..... > send_message(message) > answer=pause > .... > send_message(message) > answer=pause > .... > end > > module ServerComm > def data_receive(data) > message=F(data) > sp=Q(message) > sp.notify(message) > end > end > > In my server I can have many spawn process. In Q function I use a uuid to > find or to create a spawned process > send_message send over the network and after I want to wait a answer. > > I don''t known how to write the pause function. > Where I can find the right documentation ? > > > regards,guillaume > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-- Thanks! -=R
Aman Gupta
2008-Nov-23 12:18 UTC
[Eventmachine-talk] How can I create synchrone messaging system
EM is asynchronous in nature, and does not provide an easy way to do blocking reads. If you are using ruby 1.9, you can try the Fiber API which provides a Fiber.yield that you can use to pause. Also note that EM.spawn does not actually spawn processes or threads. It will not make your program concurrent and its use is generally not recommended. Aman On Fri, Nov 21, 2008 at 8:22 AM, Guillaume Dorchies < guillaume.dorchies at gmail.com> wrote:> Hello > > I try to do something like that > > sp=EM.spawn do > ..... > send_message(message) > answer=pause > .... > send_message(message) > answer=pause > .... > end > > module ServerComm > def data_receive(data) > message=F(data) > sp=Q(message) > sp.notify(message) > end > end > > In my server I can have many spawn process. In Q function I use a uuid to > find or to create a spawned process > send_message send over the network and after I want to wait a answer. > > I don''t known how to write the pause function. > Where I can find the right documentation ? > > > regards,guillaume > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20081123/0d4ba844/attachment.html>
Guillaume Dorchies
2008-Nov-24 08:18 UTC
[Eventmachine-talk] How can I create synchrone messaging system
Ok thanks, I will try with fiber 2008/11/23 Aman Gupta <themastermind1 at gmail.com>> EM is asynchronous in nature, and does not provide an easy way to do > blocking reads. If you are using ruby 1.9, you can try the Fiber API which > provides a Fiber.yield that you can use to pause. > Also note that EM.spawn does not actually spawn processes or threads. It > will not make your program concurrent and its use is generally not > recommended. > > Aman > > On Fri, Nov 21, 2008 at 8:22 AM, Guillaume Dorchies < > guillaume.dorchies at gmail.com> wrote: > >> Hello >> >> I try to do something like that >> >> sp=EM.spawn do >> ..... >> send_message(message) >> answer=pause >> .... >> send_message(message) >> answer=pause >> .... >> end >> >> module ServerComm >> def data_receive(data) >> message=F(data) >> sp=Q(message) >> sp.notify(message) >> end >> end >> >> In my server I can have many spawn process. In Q function I use a uuid to >> find or to create a spawned process >> send_message send over the network and after I want to wait a answer. >> >> I don''t known how to write the pause function. >> Where I can find the right documentation ? >> >> >> regards,guillaume >> >> >> _______________________________________________ >> Eventmachine-talk mailing list >> Eventmachine-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/eventmachine-talk >> > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20081124/d732b75b/attachment.html>
Roger Pack
2008-Nov-24 08:22 UTC
[Eventmachine-talk] How can I create synchrone messaging system
there are some good old posts with fibered stuffs http://oldmoe.blogspot.com/ GL! -=R On Mon, Nov 24, 2008 at 9:18 AM, Guillaume Dorchies <guillaume.dorchies at gmail.com> wrote:> Ok thanks, I will try with fiber > > > > 2008/11/23 Aman Gupta <themastermind1 at gmail.com> >> >> EM is asynchronous in nature, and does not provide an easy way to do >> blocking reads. If you are using ruby 1.9, you can try the Fiber API which >> provides a Fiber.yield that you can use to pause. >> Also note that EM.spawn does not actually spawn processes or threads. It >> will not make your program concurrent and its use is generally not >> recommended. >> Aman >> >> On Fri, Nov 21, 2008 at 8:22 AM, Guillaume Dorchies >> <guillaume.dorchies at gmail.com> wrote: >>> >>> Hello >>> >>> I try to do something like that >>> >>> sp=EM.spawn do >>> ..... >>> send_message(message) >>> answer=pause >>> .... >>> send_message(message) >>> answer=pause >>> .... >>> end >>> >>> module ServerComm >>> def data_receive(data) >>> message=F(data) >>> sp=Q(message) >>> sp.notify(message) >>> end >>> end >>> >>> In my server I can have many spawn process. In Q function I use a uuid to >>> find or to create a spawned process >>> send_message send over the network and after I want to wait a answer. >>> >>> I don''t known how to write the pause function. >>> Where I can find the right documentation ? >>> >>> >>> regards,guillaume >>> >>> >>> _______________________________________________ >>> Eventmachine-talk mailing list >>> Eventmachine-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/eventmachine-talk >> >> >> _______________________________________________ >> Eventmachine-talk mailing list >> Eventmachine-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/eventmachine-talk > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-- Thanks! -=R