lgierth / promise.rb

Promises/A+ for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event Machine

rixlabs opened this issue · comments

Hi,

I opened an Issue but I just need some help relate to promise.rb.
I know and use Promises with q.js and I was trying a ruby equivalent.

I'm not an expert with EM but I tried the first examples and I never get the output printed.

It's possible that I have to wrap the execution of nonblocking_stuff methods with an EM.run?

EM.run do
   nonblocking_stuff.then { |value| p value }
   nonblocking_stuff.then(proc { |value| p value })
end

Maybe it's just me

Thank you.

Exactly, EM.run should do the trick. Although if the supplied block finishes before the callbacks get a chance to get executed, they'll just get discarded. The examples are to be thought of as being part of a larger program that runs in an eventloop, e.g. a webserver or background worker.

Ok thanks!

tomorrow I'll send you a pull request with a new version of the examples.