Adding tasks to the event queue

25 views
Skip to first unread message

Arindam Mukherjee

unread,
Jul 16, 2016, 10:08:37 PM7/16/16
to EventMachine
I am new to EventMachine and am integrating it with a Rails application. I intend to use the EventMachine reactor for connecting over AMQP (ruby-amqp), http/s as well as other protocols.

I start the EM loop in a separate thread, initialized via a Rails initializer script. But thereafter, if I intend to add new channels / queues, or connect to URLs, how do I add these resources to the EM reactor?

1. Is it using EM.next_tick?
2. Is it by encapsulating access to the resource using a deferrable?
3. Is it using EM::Queues?

Regards,
Arindam

James Tucker

unread,
Jul 16, 2016, 10:17:26 PM7/16/16
to eventm...@googlegroups.com
On Sun, Jul 3, 2016 at 5:14 AM, Arindam Mukherjee <arindam....@gmail.com> wrote:
I am new to EventMachine and am integrating it with a Rails application. I intend to use the EventMachine reactor for connecting over AMQP (ruby-amqp), http/s as well as other protocols.

I recommend against this. Run your async code in a separate daemon. To write from amqp from a rails app, you're likely better off with something like bunny.

I start the EM loop in a separate thread, initialized via a Rails initializer script. But thereafter, if I intend to add new channels / queues, or connect to URLs, how do I add these resources to the EM reactor?

1. Is it using EM.next_tick?

You can use the EM.schedule API to send tasks to the reactor safely.
 
2. Is it by encapsulating access to the resource using a deferrable?

A deferrable object in EM is just a sort of promise. It makes no attempt to address concurrency, locality, etc. It's just a container for some callbacks.
 
3. Is it using EM::Queues?

EM::Queue is a convenience that does encapsulate running tasks on the reactor thread. It is safe to push to EM::Queue from other threads.
 

Regards,
Arindam

--
You received this message because you are subscribed to the Google Groups "EventMachine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eventmachine...@googlegroups.com.
To post to this group, send email to eventm...@googlegroups.com.
Visit this group at https://groups.google.com/group/eventmachine.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages