Created
June 25, 2015 19:56
-
-
Save ghiden/ccbf414148a19bc76ab2 to your computer and use it in GitHub Desktop.
Bluebird delay behaviors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'); | |
function test1() { | |
return new Promise(function(resolve) { | |
setTimeout(function() { | |
console.log('resolve'); | |
resolve(100); | |
}, 500); | |
}); | |
} | |
var result = test1().delay(500); | |
console.log(result.isPending()); | |
setTimeout(function() { | |
console.log(result.isPending()); | |
}, 800); | |
setTimeout(function() { | |
console.log(result.isPending()); | |
console.log(result.value()); | |
}, 1500); | |
/////////////////////////////////////////////// | |
function test2() { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('reject'); | |
reject(new Error('failed')); | |
}, 500); | |
}); | |
} | |
setTimeout(function() { | |
console.log('\n\ntesting reject'); | |
var result = test2().delay(500); | |
console.log(result.isPending()); | |
setTimeout(function() { | |
console.log(result.isPending()); | |
}, 800); | |
setTimeout(function() { | |
console.log(result.isPending()); | |
console.log(result.reason()); | |
}, 1500); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment