Skip to content

Commit

Permalink
use native Promise.race in Task.getRaceMonoid
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 8, 2020
1 parent 551c5fc commit dbe37fb
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,7 @@ export function getMonoid<A>(M: Monoid<A>): Monoid<Task<A>> {
*/
export function getRaceMonoid<A = never>(): Monoid<Task<A>> {
return {
concat: (x, y) => () =>
new Promise((resolve, reject) => {
let running = true
const resolveFirst = (a: A) => {
if (running) {
running = false
resolve(a)
}
}
const rejectFirst = (e: any) => {
if (running) {
running = false
reject(e)
}
}
x().then(resolveFirst, rejectFirst)
y().then(resolveFirst, rejectFirst)
}),
concat: (x, y) => () => Promise.race([x(), y()]),
empty: never
}
}
Expand Down

0 comments on commit dbe37fb

Please sign in to comment.