Skip to content

Instantly share code, notes, and snippets.

@thejhh
Last active December 10, 2015 02:38
Show Gist options
  • Select an option

  • Save thejhh/4369095 to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/4369095 to your computer and use it in GitHub Desktop.
Promise test
{
"name": "promise-test",
"version": "0.0.1",
"description": "Promise test",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"author": "Jaakko-Heikki Heusala <jheusala@iki.fi>",
"license": "MIT",
"dependencies": {
"q": "*"
},
"private": true
}
var Q = require('q');
Q.fcall(function() {
throw new Error("Hello");
}).then(function() {
console.log('1st resolved');
}, function(err) {
console.error('ERROR: 1st:', err);
}).then(function() {
console.log('2nd resolved');
}, function(err) {
console.error('ERROR: 2nd:', err);
}).done();
// $ node test.js
// ERROR: 1st: [Error: Hello]
// 2nd resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment