Skip to content

Instantly share code, notes, and snippets.

@rkatic
Last active December 20, 2015 08:39
Show Gist options
  • Save rkatic/6102488 to your computer and use it in GitHub Desktop.
Save rkatic/6102488 to your computer and use it in GitHub Desktop.
var asap = require("asap")
asap.sub = function (onerror) {
var parent = this;
var self = function (task) {
parent(function () {
try {
task();
} catch (e) {
if (self.onerror) {
self.onerror(e);
} else {
throw e;
}
}
});
};
self.onerror = onerror;
self.sub = parent.sub;
return self;
};
module.exports = asap.sub.bind(asap);
// asap for easier debugging in browsers.
var asap = require("asap.sub")(function (e) {
if (typeof window !== "undefined") {
if (window.console && console.error) {
console.error(e);
return;
}
}
throw e;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment