(NodeJS 6.1, Bluebird 3.3.5)
I tried using Promise.using with locks from rwlock. Imho in that scenario I do not really have a resource that i need to pass to my code, so I went with (removed everything related to rwlock to show the bluebird relevant part only):
var Promise = require("bluebird");
function writeLockDisposer() {
return Promise
.resolve(null) // will work instead: .resolve({})
.disposer(function () { console.log("won't see me :/"); });
};
function withWriteLock(fn) {
return Promise.using(writeLockDisposer(), fn);
};
withWriteLock(function () {
return Promise.resolve("you'll see me");
}).then(function () {
console.log("and you'll also see mee");
});
I'm rather new to JS and Node, so I might just not know some conventions like "you never fulfill a promise with null", but I found this behaviour somewhat strange after reading the documentation:
In conjunction with .disposer, using will make sure that no matter what, the specified disposer will be called when the promise returned by the callback passed to using has settled.
(NodeJS 6.1, Bluebird 3.3.5)
I tried using Promise.using with locks from rwlock. Imho in that scenario I do not really have a resource that i need to pass to my code, so I went with (removed everything related to rwlock to show the bluebird relevant part only):
I'm rather new to JS and Node, so I might just not know some conventions like "you never fulfill a promise with null", but I found this behaviour somewhat strange after reading the documentation: