I''ve been using a loop within a defer when I need to fire off a timer from inside EM after it''s running. Is there a way to do this using the built in timers? For an example of what I need it for, I setup a monitoring queue inside stompserver, and if a client is subscribed to the monitor queue I want to fire off a status message every so many seconds. Right now I just have a defer loop that runs through all the active subscribers every few seconds. Works fine and nothing wrong with it that I can see, but if there is a way to use the built in timers it would be a bit cleaner. Chris
On 10/22/06, snacktime <snacktime at gmail.com> wrote:> > I''ve been using a loop within a defer when I need to fire off a timer > from inside EM after it''s running. Is there a way to do this using > the built in timers? For an example of what I need it for, I setup a > monitoring queue inside stompserver, and if a client is subscribed to > the monitor queue I want to fire off a status message every so many > seconds. Right now I just have a defer loop that runs through all the > active subscribers every few seconds. Works fine and nothing wrong > with it that I can see, but if there is a way to use the built in > timers it would be a bit cleaner.Can you just set up a periodic timer to fire every couple of seconds and poll the active connections? I think I''m missing something important here. At the risk of stating the obvious, you can call #add_timer or #add_periodic_timer anytime you want, even after EM is running. (One missing feature is #cancel_timer... I ought to get that in there one of these days.) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20061022/f922b649/attachment-0001.html
> Can you just set up a periodic timer to fire every couple of seconds and > poll the active connections? I think I''m missing something important here. > At the risk of stating the obvious, you can call #add_timer or > #add_periodic_timer anytime you want, even after EM is running.I assumed that you couldn''t start a timer just anywhere, such as inside an instance of a module/class that EM is running. When I try I always get the following: terminate called after throwing an instance of ''std::runtime_error'' what(): not initialized Abort trap: 6 (core dumped)
On 10/22/06, snacktime <snacktime at gmail.com> wrote:> > > Can you just set up a periodic timer to fire every couple of seconds and > > poll the active connections? I think I''m missing something important > here. > > At the risk of stating the obvious, you can call #add_timer or > > #add_periodic_timer anytime you want, even after EM is running. > > I assumed that you couldn''t start a timer just anywhere, such as > inside an instance of a module/class that EM is running. When I try I > always get the following: > > terminate called after throwing an instance of ''std::runtime_error'' > what(): not initialized > Abort trap: 6 (core dumped) > _______________________________________________Can you put up a complete code sample that does that? According to the source, the only way to get that error is to call an EM while the EM loop is not running. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20061022/aea18417/attachment.html
> Can you put up a complete code sample that does that? According to the > source, the only way to get that error is to call an EM while the EM loop is > not running. >Umm you''re right, it was being called outside of the EM loop.