Created
September 14, 2016 12:26
-
-
Save webpapaya/f5b331d58fd296c029ff23be8ee5d88b to your computer and use it in GitHub Desktop.
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
export const executeAndReturn = (fn) => { | |
return (argument) => { | |
fn(); | |
return argument; | |
} | |
}; |
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
// Without executeAndReturn utility | |
const myFn = () => console.log('my fancy calculation') | |
Promise.resolve('my resolved promise') | |
.then((value) => { | |
myFn(); | |
return value; | |
}) | |
.then((promiseValue) => console.log(promiseValue)); | |
// => "my fancy calculation" | |
// => "my resolved promise" | |
// With executeAndReturn utility | |
import { executeAndReturn } from 'promise-utils.js'; | |
const myFn = () => console.log('my fancy calculation') | |
Promise.resolve('my resolved promise') | |
.then(executeAndReturn(myFn)) | |
.then((promiseValue) => console.log(promiseValue)); | |
// => "my fancy calculation" | |
// => "my resolved promise" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment