Last active
January 1, 2020 17:29
-
-
Save yarastqt/582bdc9c96e1dd1da4fbc1a0b1b14025 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 future = executor => ({ | |
chain(fn) { | |
return future((resolve, reject) => | |
this.fork( | |
value => fn(value).fork(resolve), | |
error => reject(error), | |
) | |
) | |
}, | |
map(fn) { | |
return this.chain(value => future.of(fn(value))) | |
}, | |
fork(resolve, reject) { | |
executor(resolve, reject) | |
return this | |
}, | |
promise() { | |
return new Promise((resolve, reject) => { | |
this.fork(resolve, reject) | |
}) | |
}, | |
}) | |
future.of = value => future(fn => fn(value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Отличия Future от Promise