Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active December 26, 2015 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/7061368 to your computer and use it in GitHub Desktop.
Save domenic/7061368 to your computer and use it in GitHub Desktop.
Potential promise pipelining with subclassing
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