Last active
November 15, 2015 06:10
-
-
Save AyaMorisawa/69db2d176b4c6a25bafe 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
// Task | |
const logTask = Task.sync<string, void>(text => console.log(text)); | |
const taskA = Task.delay(1000).map(() => 1 + 2 + 3).map(String); | |
const taskB = Task.resolve('Hello'); | |
Task.all([taskA, taskB]).map(xs => xs.join(', ')).next(logTask).run(); | |
Task.race([taskA, taskB]).next(logTask).run(); | |
// Promise | |
const logPromise = (text: string) => console.log(text); | |
const promiseA = new Promise<void>(resolve => setTimeout(resolve, 1000)).then(() => 1 + 2 + 3).then(String); | |
const promiseB = Promise.resolve('Hello'); | |
Promise.all([promiseA, promiseB]).then(xs => xs.join(', ')).then(logPromise); | |
Promise.race([promiseA, promiseB]).then(logPromise); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment