lgierth / promise.rb

Promises/A+ for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change Group#promise? to check respond_to?(:then)

singpolyma opened this issue · comments

That way we can use things which do not inherit from Promise but which obey the interface with helpers like all

Promise.all isn't just implemented by calling then on the passed objects. It is kind of possible to implement Promise.all only using then as the interface for a promise, but then sync couldn't be used on the returned promise. Another behaviour change that would be needed would be that the returned promise wouldn't be rejected as soon as any input promise is rejected.

What is the actual use case? Are you trying to integrate promise.rb with some other library that implements promises? Since there are inconsistencies in just the then method between libraries.

E.g. concurrent-ruby uses the signature def then(rescuer = nil, executor = @executor, &block) compared to promise.rb that uses def then(on_fulfill = nil, on_reject = nil, &block)

Why can't you just use Promise or a class deriving from Promise?

I thought when reading the source that all only used then, but I guess I missed something :)

I'm integrating promise.rb with EventMachine and trying to be as seamless as possible, so it would be nice if all could take an array of mixed promises and deferrables (I've monkeypatched then onto deferrable -- it converts into a promise and then uses Promise#then, so totally compatible)