3 var rawAsap = require("./raw");
7 * Calls a task as soon as possible after returning, in its own event, with
8 * priority over IO events. An exception thrown in a task can be handled by
9 * `process.on("uncaughtException") or `domain.on("error")`, but will otherwise
10 * crash the process. If the error is handled, all subsequent tasks will
13 * @param {{call}} task A callable object, typically a function that takes no
16 module.exports = asap;
19 if (freeTasks.length) {
20 rawTask = freeTasks.pop();
22 rawTask = new RawTask();
25 rawTask.domain = process.domain;
34 RawTask.prototype.call = function () {
42 // If the task throws an exception (presumably) Node.js restores the
43 // domain stack for the next event.
48 // We use try/finally and a threw flag to avoid messing up stack traces
49 // when we catch and release errors.
51 // In Node.js, uncaught exceptions are considered fatal errors.
52 // Re-throw them to interrupt flushing!
53 // Ensure that flushing continues if an uncaught exception is
54 // suppressed listening process.on("uncaughtException") or
55 // domain.on("error").
56 rawAsap.requestFlush();
58 // If the task threw an error, we do not want to exit the domain here.
59 // Exiting the domain would prevent the domain from catching the error.