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

Questions about implementation #213

Closed
alexbyk opened this issue Oct 7, 2015 · 2 comments
Closed

Questions about implementation #213

alexbyk opened this issue Oct 7, 2015 · 2 comments

Comments

@alexbyk
Copy link
Contributor

alexbyk commented Oct 7, 2015

Hi. I'm trying to implement Promises/A+ (not in JS) and need help. (I need to decide could these paragraph be ignored for the flexibility )

  1. Can someone point me what was the very first reason of this:
onFulfilled or onRejected must not be called until the execution context stack contains only platform code.

For example: avoiding deep recursion/stack overflow/etc. What else?

  1. and this:
If onFulfilled is not a function, it must be ignored.
If onRejected is not a function, it must be ignored.

Why not 'null values must be ignored'? Because in my case onFulfilled can be not a function, but callable objects (overloaded instance). Also ignoring anything doesn't feel right for me

Thanks!

@bergus
Copy link

bergus commented Oct 8, 2015

Can someone point me what was the very first reason of this:

onFulfilled or onRejected must not be called until the execution context stack contains only platform code.

Have a look at #104, #139 and all the ones linked there.
This requirement is a crude formulation of the goal "_the callback must _always* be called asynchronously*" without specifying exactly how. The primary goal is that a callback passed to .then() is guaranteed not to be executed immediately right from within the then() (convenience), the secondary goal is that no client of a promise can influence timing of callbacks to his advantage (security).
What this means in other languages, especially ones that don't use an event loop but have different concurrency models, is left to be determined by you.

Why not 'null values must be ignored'? Because in my case onFulfilled can be not a function, but callable objects (overloaded instance).

In JavaScript, a function (typeof x == "function") is exactly that: a callable object. The spec basically says: if the object is callable, use it, if not, ignore it. In other languages, especially ones with static typing, it makes sense to only allow functions as parameters in the first place - we just could not do this in JS. In your case, accepting "callable objects" (to be used) and null values (to be ignored) and nothing else is totally sensible.

@alexbyk
Copy link
Contributor Author

alexbyk commented Oct 8, 2015

@bergus thanks. this #139 is the explanation for 1) I was looking for.

@alexbyk alexbyk closed this as completed Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants