Created
May 12, 2016 04:40
-
-
Save bodhi/056845b4cef86b1054948ff60e7c971e to your computer and use it in GitHub Desktop.
Piggybacking promises
This file contains hidden or 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
| piggyback(fn) => () => { | |
| if (!fn["@@piggyback"]) { | |
| const promise = fn(); | |
| fn["@@piggyback"] = promise | |
| promise.then(() => { | |
| delete fn["@@piggyback"]; | |
| }); | |
| return promise | |
| } else { | |
| return fn["@@piggyback"].then(res => { | |
| res["@@piggybacked"] = true; | |
| return res; | |
| }) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment