Skip to content

Instantly share code, notes, and snippets.

@andrewwakeling
Last active January 2, 2016 10:49
Show Gist options
  • Save andrewwakeling/8292941 to your computer and use it in GitHub Desktop.
Save andrewwakeling/8292941 to your computer and use it in GitHub Desktop.
Comparing error reporting with Promise libraries
var foo = function () {
var promise = new Promise(function (resolve, reject, notify) {
setTimeout(function () {
resolve();
}, 100);
});
return promise;
};
<!doctype html>
<html>
<head>
<script src="bower_components/bluebird/js/browser/bluebird.js"></script>
<script src="bluebird-foo.js"></script>
<script src="invoke-foo.js"></script>
</head>
</html>
{
"name": "compare-promises",
"version": "0.0.1",
"dependencies": {
"rsvp": "3.0.1",
"q": "1.0.0",
"bluebird": "0.11.6-1"
}
}
foo().then(function () {
// The following code will cause an error.
var undefinedFunc = undefined;
undefinedFunc(null);
}, function (error) {
// This is defined for best practice only. We shouldn't be getting here.
debugger;
});
var foo = function () {
var promise = new Q.promise(function (resolve, reject, notify) {
setTimeout(function () {
resolve();
}, 100);
});
return promise;
};
<!doctype html>
<html>
<head>
<script src="bower_components/q/q.js"></script>
<script src="q-foo.js"></script>
<script src="invoke-foo.js"></script>
</head>
</html>
/**
* It is acknowleged that you can handle uncaught errors by running the following code. By default though, RSVP should not silence errors.
*
* RSVP.configure('onerror', function(e) {
* console.log(e.message);
* console.log(e.stack);
* }
*/
var foo = function () {
var promise = new RSVP.Promise(function (resolve, reject) {
setTimeout(function () {
resolve();
}, 100);
});
return promise;
}
<!doctype html>
<html>
<head>
<script src="bower_components/rsvp/rsvp.js"></script>
<script src="rsvp-foo.js"></script>
<script src="invoke-foo.js"></script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment