Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee future-turn resolutions #4

Closed
jsor opened this issue Nov 2, 2012 · 4 comments
Closed

Guarantee future-turn resolutions #4

jsor opened this issue Nov 2, 2012 · 4 comments

Comments

@jsor
Copy link
Member

jsor commented Nov 2, 2012

At the moment, we're not guaranteeing future-turn resolutions (which basically means, that callbacks should always be called asynchronously, read this).

All major JavaScript libs guarantee that (when.js does not at the moment, but will in their next major release).

We have 2 options.

  1. We do not guarantee future-turn resolutions

    We keep it simple. Methods in When can stay static and creating Deferred's is as simple as doing $d = new Deferred. We should note that in the docs, so that developers are aware that there is no guarantee about if a promise will resolve asynchronously or synchronously.

  2. We do guarantee future-turn resolutions

    This would couple React/Promise to the EventLoop (or at least to some kind of QueueProcessor for which we have an EventLoop adapter). We would have to make When non-static (and require the EventLoop or a QueueProcessor in the constructor which will be passed to Deferredinstances) and it will most probably become some kind of global entry point for creating promises and deferreds.

@jsor
Copy link
Member Author

jsor commented Nov 5, 2012

To get an idea, checkout the future-turn-resolutions branch.

Consumers of React/Promise would then most probably pass around a "global" React\Promise\When instance to create Deferreds and Promises, something like:

$when = new React\Promise\When(new React\Promise\EventLoopQueueProcessor($loop));

$deferred = $when->defer();
$promise = $when->resolve($value);

@ghost ghost assigned jsor Nov 5, 2012
@igorw
Copy link
Contributor

igorw commented Nov 6, 2012

I want to keep this ticket open until we have a specific case that would benefit from the future-turn guarantee. As I said previously, I do not like coupling promises to the loop and would like to avoid it if possible.

Another unresolved issue is that we don't even know yet if it is possible to implement a fast-enough nextTick function for the libevent and libev loops. And it doesn't make sense to merge this patch before we have an answer to that.

@jsor
Copy link
Member Author

jsor commented Apr 30, 2013

@jsor
Copy link
Member Author

jsor commented May 3, 2016

See #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants