Clarification for derived promises
# Domenic Denicola (9 years ago)
Yes.
Yes. On Tue, Jul 14, 2015 at 10:10 AM -0700, "Nicholas C. Zakas" <standards at nczconsulting.com<mailto:standards at nczconsulting.com>> wrote: Hi all, I'm trying to wrap my head around derived promises and wanted to ask for a bit of clarification around how `Promise.resolve()` works from a derived class. Consider this: ``` class MyPromise extends Promise {} var p1 = new Promise(function(resolve, reject) { resolve(42); }); var p2 = MyPromise.resolve(p1); p2.then(function(value) { console.log(value); }); ``` Am I correct in believing that: 1. `p1` is resolved upon being passed to `MyPromise.resolve()`? I believe this is what happens in 25.4.4.5 Step 6 (http://www.ecma-international.org/ecma-262/6.0/#sec-promise.resolve) 2. `p2` is an instance of `MyPromise` that is resolved with a promise value of 42. Thanks! -- ___________________________ Nicholas C. Zakas http://www.nczonline.net _______________________________________________ es-discuss mailing list es-discuss at mozilla.org https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150714/6566d31a/attachment.html>
# Nicholas C. Zakas (9 years ago)
Awesome, thank you!
Awesome, thank you! -N On 7/14/2015 10:12 AM, Domenic Denicola wrote: > > Yes. > > > > > On Tue, Jul 14, 2015 at 10:10 AM -0700, "Nicholas C. Zakas" > <standards at nczconsulting.com <mailto:standards at nczconsulting.com>> wrote: > > Hi all, > > I'm trying to wrap my head around derived promises and wanted to ask for > a bit of clarification around how `Promise.resolve()` works from a > derived class. Consider this: > > ``` > class MyPromise extends Promise {} > > var p1 = new Promise(function(resolve, reject) { > resolve(42); > }); > > var p2 = MyPromise.resolve(p1); > p2.then(function(value) { > console.log(value); > }); > ``` > > Am I correct in believing that: > > 1. `p1` is resolved upon being passed to `MyPromise.resolve()`? I > believe this is what happens in 25.4.4.5 Step 6 > (http://www.ecma-international.org/ecma-262/6.0/#sec-promise.resolve) > 2. `p2` is an instance of `MyPromise` that is resolved with a promise > value of 42. > > Thanks! > > -- > ___________________________ > Nicholas C. Zakas > http://www.nczonline.net > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -- ___________________________ Nicholas C. Zakas http://www.nczonline.net -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150714/158d1928/attachment.html>
# C. Scott Ananian (9 years ago)
And --- apologies for continuing to beat this drum --- you can look at the
prfun
package on npm for a practical example of this use of Promise
subclasses and resolve
.
If other folks know of other libraries using these features, let me know so I can recommend other people's code as well as my own. ;)
And --- apologies for continuing to beat this drum --- you can look at the `prfun` package on npm for a practical example of this use of Promise subclasses and `resolve`. If other folks know of other libraries using these features, let me know so I can recommend other people's code as well as my own. ;) --scott -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150714/817ba412/attachment.html>
I'm trying to wrap my head around derived promises and wanted to ask for a bit of clarification around how
Promise.resolve()
works from a derived class. Consider this:Am I correct in believing that:
p1
is resolved upon being passed toMyPromise.resolve()
? I believe this is what happens in 25.4.4.5 Step 6 (www.ecma-international.org/ecma-262/6.0/#sec-promise.resolve)p2
is an instance ofMyPromise
that is resolved with a promise value of 42.