Created
May 4, 2016 18:50
-
-
Save hazeledmands/da4ac6d4d2d9bccb93c380aa7ce0fd1e to your computer and use it in GitHub Desktop.
Tests on bluebird disposers
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
const Promise = require('bluebird'); | |
console.log('starting promise'); | |
Promise.resolve() | |
.then(function () { | |
console.log('grabbing resource'); | |
return Promise.using(getDisposer(), function () { | |
console.log('starting delay'); | |
return Promise.delay(2000) | |
.then(function () { | |
console.log('ending delay'); | |
}); | |
}) | |
.then(function () { | |
console.log('finished with resource'); | |
}); | |
}) | |
.timeout(1000) | |
.then(function () { | |
console.log('done!'); | |
}) | |
.catch(function (err) { | |
console.log(err.stack); | |
}); | |
function getDisposer () { | |
const resource = {}; | |
console.log('getting disposer'); | |
return Promise.resolve(resource) | |
.disposer(function () { | |
console.log('disposing!'); | |
}); | |
} |
Author
hazeledmands
commented
May 4, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment