tmm1 / amqp

AMQP client implementation in Ruby/EventMachine
http://groups.google.com/group/ruby-amqp
443 stars 5 forks source link

Raising an exception within AMQP #36

Closed sriram closed 13 years ago

sriram commented 13 years ago

Hello,

I have an use case in which I need to raise an exception with an event machine loop. But on doing so the entire process hangs and become unresponsive.

Any suggestion on how to raise and catch exceptions within an event loop?

Thanks Sriram.

botanicus commented 13 years ago

Sriram, this is not a mailing list or IRC, please next time ask there. You can use exceptions as long as you don't have any async code in begin/rescue block. For async code, there should be an option to handle exceptions via callback. I'm not so familiar with EventMachine, but i. e. in Node.js you have code like:

fs.unlink('/tmp/hello', function (err) {
  if (err) throw err;
  console.log('successfully deleted /tmp/hello');
});

So you'll simply get an exception instance to the callback so you can handle it (so it's passed as an argument, not raised!). In EventMachine, I believe, defferable objects has #errback method, so you can do mydef.callback { # what'll happen on success } and mydef.errback { |error| # what'll happen on error }. But I don't remember exactly, check the documentation.