Make methods return bluebird promise instead native promise#76
Make methods return bluebird promise instead native promise#76BnayaZil wants to merge 4 commits into
Conversation
benjamingr
left a comment
There was a problem hiding this comment.
Can you please write tests that assert that the promise is bluebird-api and assert the changes you make change those tests from failing to passing?
| })()); | ||
| }; | ||
|
|
||
| Bluebird.call = (o, ...args) => Bluebird.resolve(o).call(...args); |
There was a problem hiding this comment.
This change seems unnecessary.
| @@ -1,5 +1,8 @@ | |||
| module.exports = (Bluebird) => { | |||
| Bluebird.any = (prom, n) => Bluebird.resolve(prom).any(); | |||
There was a problem hiding this comment.
This change seems unnecessary.
There was a problem hiding this comment.
But Bluebird.resolve already returns a bluebird instance, so why would wrapping help?
There was a problem hiding this comment.
Because you resolve before you do the any, you need to resolve the any values.
There was a problem hiding this comment.
But .any() already returns a bluebird promise.
| Bluebird.prototype.delay = function delay(ms) { | ||
| return this.then(obj => new Bluebird((onFulfilled) => setTimeout(() => onFulfilled(obj), ms))); | ||
| } | ||
| Bluebird.delay = (ms, o) => Bluebird.resolve(o).delay(ms); |
There was a problem hiding this comment.
This change seems unnecessary.
| })()); | ||
| }; | ||
| Bluebird.prototype.each = function each(iterator) { | ||
| return Bluebird.resolve((async () => { |
There was a problem hiding this comment.
Was anything actually changed here?
| @@ -1,6 +1,9 @@ | |||
| const util = require("./util"); | |||
| module.exports = (Bluebird) => { | |||
| Bluebird.filter = (x, predicate, opts) => Bluebird.resolve(x).filter(predicate, opts); | |||
There was a problem hiding this comment.
This change seems unnecessary.
There was a problem hiding this comment.
But Bluebird.resolve already returns a bluebird instance, so why would wrapping help?
There was a problem hiding this comment.
Because you resolve before you do the filter, you need to resolve the filter values.
There was a problem hiding this comment.
But p.filter(predicate) already returns a bluebird promise.
There was a problem hiding this comment.
They are not, filter, each and map didn't return bluebird promise, I have tested it.
I can move bluebird resolve wrapper to the prototype functions if it seems cleaner to you.
There was a problem hiding this comment.
Can you add a test so we can see?
| })()); | ||
| }; | ||
|
|
||
| Bluebird.mapSeries = (promise, iterator) => Bluebird.resolve(promise).mapSeries(iterator); |
There was a problem hiding this comment.
This change seems unnecessary.
| return ret; | ||
| })()); | ||
| }; | ||
| Bluebird.props = o => Bluebird.resolve(o).props(); |
There was a problem hiding this comment.
This change seems unnecessary.
| })()); | ||
| }; | ||
|
|
||
| Bluebird.reduce = (promise, reducer, initialValue) => Bluebird.resolve(promise).reduce(reducer, initialValue); |
There was a problem hiding this comment.
This change seems unnecessary.
| @@ -1,5 +1,8 @@ | |||
| module.exports = (Bluebird) => { | |||
| Bluebird.some = (prom, n) => Bluebird.resolve(prom).some(n); | |||
There was a problem hiding this comment.
This change seems unnecessary.
| return winner; | ||
| })()); | ||
| } | ||
| Bluebird.timeout = (ms, rejectDesc, o) => Bluebird.resolve(o).delay(ms) |
There was a problem hiding this comment.
This change seems unnecessary.
|
The |
|
@benjamingr I add tests to make sure the promises from the prototype returns a non-bluebird instance. |
Solve #72
#goodnessSquad