Last active
December 26, 2015 00:08
-
-
Save domenic/7061368 to your computer and use it in GitHub Desktop.
Potential promise pipelining with subclassing
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 p0 = Promise.cast(null); | |
var p1 = p0.then(() => remotePromise); | |
var p2 = p1.invoke("foo"); | |
line 2 calls remotePromise's .then method, like so: | |
remotePromise.then(v => { set p1's [[Value]] to v }, r => { set p1's [[Reason]] to r }) | |
it ALSO stores remotePromise in [[Following]] | |
Once remotePromise settles, i.e. once one of the two above callbacks gets called, | |
[[Following]] gets cleared. | |
The second half: what does p1.invoke (=== Promise.prototype.invoke) do. The answer: | |
- Checks if its [[Following]] is a promise; | |
if so, returns [[Following]].invoke(...args), | |
or possibly Promise.cast([[Following]].invoke(...args). | |
- Otherwise, falls back to Reflect.invoke([[Value]], ...args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment