-
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
done
#5
Comments
This works well, although it can be frustrating when you forget to add a |
Static analysis may also help catch missing |
hmm, but if any object that has a method |
I'm strongly against requiring something like Also, it seems impossible to introduce Personally, I'm much more interested in something like #2. |
I think we need something to help support going back to node-style callbacks. Since done style callbacks crash on error, there needs to be a way of escaping promises. It doesn't need to hit quite the level that |
The solution employed by Q and WinJS is a function called
done
on each promise, which is much likethen
except it signals that if there is an unhandled rejection for that promise, the program should crash. That is:Notably,
p.done(f, r)
is equivalent top.then(f, r).done()
, so you can choose either style as convenient; the latter is a bit nicer for refactoring, but the former signals intent nicely in other situations.Also,
done
returnsundefined
.The guidance is that when creating a promise (either directly or via
then
), you should always either (a)return
that promise so that the caller takes care of it, or (b) call.done()
on it.For more info on this see the MSDN article: http://msdn.microsoft.com/en-us/library/windows/apps/hh700337.aspx
Notably, this idea is composable with other ideas: if you "cap" a promise with
.done()
, that handles the rejection immediately with a sort of "default behavior" (i.e. crashing). So the other ideas can still be implementing to catch cases where you forget to cap.In other words, this idea reduces the number of unhandled rejections present in a program, and with inhuman programmer diligence brings that number down to zero. But in cases where that number is not brought down to zero, other ideas still apply.
The text was updated successfully, but these errors were encountered: