Skip to content

Instantly share code, notes, and snippets.

@bodhi
Created May 12, 2016 04:40
Show Gist options
  • Select an option

  • Save bodhi/056845b4cef86b1054948ff60e7c971e to your computer and use it in GitHub Desktop.

Select an option

Save bodhi/056845b4cef86b1054948ff60e7c971e to your computer and use it in GitHub Desktop.
Piggybacking promises
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