From: es-discuss <[email protected]> on behalf of David Bruant
<[email protected]>
> Domain#intercept which looks at the Node error convention (error in async
> callback first argument) certainly suffer from the same issue, but looks
> practical enough. I lack the experience with Node domains. If some have it,
> it'd be interesting to share it.
`Domain.prototype.intercept` is a rarely-used feature of domains. Wrapping your
callbacks in `domain.intercept` before passing them to a callback-accepting
function is akin to attaching an error handler to a promise that always puts
the error inside an error-storage box ("domain") which you or someone else can
centrally handle later. I do not think it's particularly relevant to
error-handling discussions.
The value of domains comes in them being a global switch you can turn on that
allows all errors thrown within a given request/response cycle to be caught in
a single place. (With certain problematic edge-case exceptions to this rule.)
This allows you to associate "uncaught errors" with the request/response cycle
in question, as opposed to the browser's `window.onerror` where you get no real
context as to what caused the exception. This is especially important in Node
where the same function (e.g. a HTTP server's request handler) can be called
thousands of times at once, with different data, so the stack trace alone is
not useful.
More detail in [a presentation I
gave](http://www.slideshare.net/domenicdenicola/domains-20010482) a while back.
Domains are considered something of a band-aid and are being subsumed into a
more general "async listener" API in Node.js 0.12. The async listener API gives
you the ability to add AOP-style before/after handlers for any async operation
in Node.js. (I believe libraries like Google's Closure accomplish this in the
browser already, by wrapping all async APIs.) Domains will be re-implemented on
top of async listeners for backward compatibility, but async listener is the
new primitive for async interception of the type that domains were a special
case of.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss