-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fulfill, reject, adopt? #12
Comments
If I was going to go that route I'd be inclined to drop |
I'm obviously a big fan of the polymorphic resolve/reject right now, but I'm also a fan of simple, so I definitely think this is worth talking through. Aside from the polymorphic resolve/reject preventing promises-for-promises, one thing I like about them is that, at least in my mind, they kind of just "do what I mean". Pass anything to them, and they work it out, and personally, I prefer As @ForbesLindesay pointed out, since One thing that bothers me about that is polymorphic resolve matches well with Another oddity is that we'd be allowing fulfill/reject to sync throw to indicate you violated a precondition, but we decided not to do that for |
Some things that seem important:
So, my thinking is that ideally we should either disallow promises-for-promises in all cases, or allow them in all cases. Preventing promises-for-promises
Allowing promises-for-promises
|
How often do you take advantage of this? That is, how often do you have a value that you're not sure whether it's a promise or a non-promise? Personally, I can't think of a time that's ever been true for me.
It's becoming increasingly clear to me that the resolvers spec is going to have a "normative optional" section. That is, implement this core, and if you want to implement this other sugar, implement it like we say. For example if we went with a minimal proposal like in #10, we'd probably want to spec
At first I had this doubt too, but then I realized that the reason I was so strongly against throwing with var p = new Promise(function (resolver) {
resolver.fulfill(5);
});
// Promise gets fulfilled immediately and we can synchronously inspect that:
assert("value" in p && p.value === 5);
p.then(function () {
// But this callback is stilled called in a future turn.
});
I don't think these things were ever symmetric to begin with, especially after the introduction of polymorphic And yes, I think ditching polymorphic The more I think about this idea, the more I like it. It avoids so much complexity but still prevents promises-for-promises. |
I agree with @domenic on everything except:
I have occasionally used that, but I could definitely live without it.
If you replace Even if ditching polymorphic |
Well, as I said in #10 (comment), if it's polymorphic it can't be called |
It seems like polymorphic |
Indeed, I don't think this is valuable anymore as-written. If we were inclined to specify an optional |
In #11, I outline how the polymorphic resolver API is pedagogically problematic. I still see the attraction of disallowing promises-for-promises though. Could we perhaps do so as follows?
fulfill(x)
: throws if given a promisereject(x)
: throws if given a promiseadopt(p)
: throws if not given a promiseWe'd probably also need
resolve(x)
which doesn't throw, since that behavior is useful. On the other hand, I don't think a polymorphic reject is useful behavior, even if it is proposed in promises-aplus/promises-spec#66.The text was updated successfully, but these errors were encountered: