-
Notifications
You must be signed in to change notification settings - Fork 0
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
Lazy promises (making done
compulsory)
#8
Comments
From my comment in #2: The concept is interesting, indeed. I'm not caught up yet on the Hot and Cold promises thread, but my initial reaction is that lazy promises are something that could easily be built on top of a current Promises/A+ promise. It feels weird to me initially to have this integrated this directly into Promises/A+ promises as they exist today. |
@ForbesLindesay note that this is exactly what gozala/recuders does. I sometimes fall in to the trap of not calling the reducers equivelant of Coming from node callbacks and event emitters I find their error handling correct. Event emitters throw if I don't handle it. callbacks push the error directly in my face every single time. Reducers has a very similar model to streams, if you start the stream by folding (equivelant of |
@briancavalier Yes, hot and cold promises could be built directly on top of the current promises/A+ spec and would indeed still be valid promises (providing calling |
Ass suggested by @Raynos in #2 we could make promises lazy until
.done
is called. Consider thepromise(executor)
syntax being proposed in promises-aplus/constructor-spec#3The executor is a function which initiates the asynchronous operation. It has the potential to generate either a resolved promise or a rejected promise. If it's not called, then no rejected promise can exist, so we don't have an issue. So the key idea being presented here is to only call it when we know the promise's rejection will be handled.
By only calling the executor once
.done
is called, you can guarantee that.done
will always be called for all promises. If.done
is not called, the entire function will fail to do anything, which will be easy to quickly pick up when developing.Having done that, it's a simple case of having
.done
behave as in #5 and crash the application appropriately by throwing the exception in the next turn of the event loop.Transition
Step 1, ad
.done
to the promises spec.Step 2, make sure all promise libraries call
.done
if present when assimilating promises.Step 3, wait a month or so for this to be true of most major promise libraries
Step 4, begin using
console.warn
to warn people that they need to begin calling.done
when.done
is not called after a period of a few seconds.Step 5, Implement this feature properly by making the promises lazy.
The text was updated successfully, but these errors were encountered: