Skip to content

Instantly share code, notes, and snippets.

@AyaMorisawa
Last active November 15, 2015 06:10
Show Gist options
  • Save AyaMorisawa/69db2d176b4c6a25bafe to your computer and use it in GitHub Desktop.
Save AyaMorisawa/69db2d176b4c6a25bafe to your computer and use it in GitHub Desktop.
// 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