Last active
May 20, 2017 00:18
-
-
Save rlucha/f0a444cb4055871eefe580e6521117ce 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
| // const a = _ => new Promise((resolve, reject) => resolve(2)); | |
| // const b = x => new Promise((resolve, reject) => resolve(x+10)); | |
| // a().then(m => b(m).then(z => console.log(z))); | |
| async function fn() { | |
| const a = await promiseWrapper(fakeNetworkFn, 10); | |
| const b = await promiseWrapper(fakeNetworkFn, a); | |
| return b; | |
| } | |
| const fakeNetworkFn = (params, lcb) => { | |
| const data = 5 + params; | |
| setTimeout(() => lcb(_, data), 300); | |
| } | |
| const promiseWrapper = (fn, params, cb) => new Promise((resolve, reject) => fn(params, (err, data) => resolve(data))) | |
| fn().then(e => console.log(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment