Bill Kelly
2007-Dec-02 11:32 UTC
[Eventmachine-talk] connection_completed never called afterpopen
From: Michael S. Fischer> > class Executor < EventMachine::Connection > attr_accessor :command, :param > > def self.popen(command, param) > conn = EventMachine::popen(command, self) do |conn| > conn.command = command > conn.param = param > end > end > > def post_init > puts "#{@param}" # Race condition: @param not defined yet -> exception thrown > end > endFor what it''s worth, in cases like this I typically add a custom init method, #owner_init: class Executor < EventMachine::Connection attr_accessor :command, :param def self.popen(command, param) conn = EventMachine::popen(command, self) do |conn| conn.owner_init(command, param) end end def owner_init(command, param) @command = command @param = param # ... do whatever other init... end end Regards, Bill
Michael S. Fischer
2007-Dec-02 16:06 UTC
[Eventmachine-talk] connection_completed never called afterpopen
On Dec 2, 2007 11:32 AM, Bill Kelly <billk at cts.com> wrote:> For what it''s worth, in cases like this I typically add a custom > init method, #owner_init: > > class Executor < EventMachine::Connection > attr_accessor :command, :param > > def self.popen(command, param) > conn = EventMachine::popen(command, self) do |conn| > conn.owner_init(command, param) > end > end > > def owner_init(command, param) > @command = command > @param = param > # ... do whatever other init... > endIn my particular application, I want to use the parameters passed in the block to popen only after the connection to the pipe was successfully established (i.e., to output a message to a log at an appropriate time) but before any data is received. Best regards, --Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20071202/88a09f93/attachment.html
Roger Pack
2007-Dec-03 12:15 UTC
[Eventmachine-talk] connection_completed never called afterpopen
Maybe save them then output them later? On Dec 2, 2007 5:06 PM, Michael S. Fischer <michael at dynamine.net> wrote:> On Dec 2, 2007 11:32 AM, Bill Kelly <billk at cts.com> wrote: > > > For what it''s worth, in cases like this I typically add a custom > > init method, #owner_init: > > > > > > class Executor < EventMachine::Connection > > attr_accessor :command, :param > > > > def self.popen (command, param) > > conn = EventMachine::popen(command, self) do |conn| > > conn.owner_init(command, param) > > end > > end > > > > def owner_init(command, param) > > @command = command > > @param = param > > # ... do whatever other init... > > end > > In my particular application, I want to use the parameters passed in the > block to popen only after the connection to the pipe was successfully > established ( i.e., to output a message to a log at an appropriate time) but > before any data is received. > > Best regards, > > --Michael > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-- -Roger Pack For God hath not given us the spirit of fear; but of power, and of love, and of a sound mind" -- 2 Timothy 1:7