-
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
Environment hooks #2
Comments
I think this is my favourite of the options presented thus far. Although it seems a shame to introduce a 'global', I'm not convinced it's truly avoidable. I think the Library hooks option would leave us having to maintain a list of compliant promises libraries. |
This feels like the right path to me, even if it involves a global. As I've said before, I'm not a fan of It also allows promise-implementation-agnostic tooling to be created. So, if your app mixes when, Q, and dojo (possibly because you are using other libs that depend on them), and each of those supports the API, your favorite debugging tool will work with all the promises in the app. The tool and its output will be familiar (tho possibly not identical) to you no matter which promises are being reported as unhandled. Of course, it means that tools need to be created :) Although, I could see promise implementations providing their own simple "debug mode" that makes use of these same APIs when no other debugging tool is present. |
Dojo already implements something akin to this, though in a somewhat broken form that was introduced too quickly. In other words, I'm in favor. |
I just realized we should probably include #3 as well, since if multiple promise libraries are active on a page, it might be useful to distinguish where they came from. |
Could just use: console.unhandledRejection(rejection, 'Q');
console.unhandledRejection(rejection, 'when.js'); |
What does this do that |
@domenic it's not obvouis what |
@Raynos sorry, the numbers are in the gh-pages version |
@domenic we both know those points should be linkable ;) |
There is a general issue of an eventual value is an error. Either it's never handled and the environment never sees it or it as some point marked as "error should have been handled" and then throws. For example with However if you just wrap or transform the reducible then it will be a no-op or an empty pass through if it's an error. Which means you solve the issue by having two sets of operations, one which allow errors to be handled later at any time and another which will throw the error if it's not handled. Of course this would still cause the same problem if you never use the latter type of operation (the consuming operation which throws errors). That issue is solved by having the wrapping operation be lazy. i.e. if it's never consumed it does nothing, forcing someone (the last person that write the eventual value somewhere) to consume it. Under the above approach I see no need for environment hooks. |
This is exactly the
This is exactly why we are trying to find other solutions, such as this one of environment hooks.
I'm not sure I understand this approach, so feel free to explain it in more detail. But I think the problem is async-ness. How do you know an error will never be consumed, in an async world? |
@domenic let's imagine that an And unless you This allows you to lazily wrap an You avoid the issue basically by saying "the asynchronous operation only starts when you call |
What I'm saying is basically that So when you create a promise you should do something like: var p = Promise(function (promise) {
// do async thing
// function only called if someone calls p.done()
return promise
}) |
That's a really really interesting idea and ties in nicely with promises-aplus/constructor-spec#8 (Hot and Cold Promises). It would be a pretty radical change, and would promote the use of |
We can continue discussing that idea in #8 as it does not really relate to Environment hooks. |
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. |
Everyone likes the environment hooks idea. I think we should standardize on it, but before we do, I think we should write a quick Chrome extension to show that it works. I admit that this has been on my weekend task list for a couple months now, without having been accomplished, so, anyone else have more free time to prototype such things? :) |
Haven't prototyped a Chrome extension, but did extract some debugging utilities from Legendary into its own package: https://github.com/novemberborn/legendary-debug. Internally Legendary's Promises will call |
Has an |
Legendary has something, see https://github.com/novemberborn/legendary/blob/master/lib/legendary.js and https://github.com/novemberborn/legendary-debug. I haven't given it much love though. |
@ricardobeat We're currently prototyping support for an |
@ricardobeat when.js >= 2.2.0 has unhandled rejection monitoring without using I don't think the API is perfect, but I think it could be a good basis for discussion here. Basically it relies on a single I'll make some time to do a quick writeup on the |
@briancavalier looking forward to the |
re: console in IE < 9. Yeah, it's a pain. Right now, when carefully sniffs for Here's a quick and dirty dump of the // Sorry for mixing JS-like and IDL, it's just easier
function PromiseStatus(); // constructor
interface PromiseStatus {
PromiseStatus observed();
void fulfilled(optional any value);
void rejected(optional any reason);
} A few interesting things:
when.js's particular implementation is here (slightly cleaned up in the dev branch as opposed to master) |
This idea involves establishing a set of standard "environment hooks" which, if present, are called upon an unhandled rejection and upon it being handled later.
The essential idea would be something like two globally-known methods, e.g.
console.unhandledRejection
,console.rejectionHandled
, which implementations call upon those two events---if they exist (and are callable). Presumably the former would give out a handle which the latter then accepts.By itself this does nothing, but if people build tools that tap into these (e.g. browser extensions), they could provide a very nice debugging experience.
The text was updated successfully, but these errors were encountered: