-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fio): zipWithPar() now resolves with the result instead of a…
…n `Exit` BREAKING CHANGE: signature of zipWithPar() has been changed.
- Loading branch information
1 parent
459a78a
commit 766e356
Showing
3 changed files
with
43 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Await} from '../main/Await' | ||
import {Exit} from '../main/Exit' | ||
import {Fiber} from '../main/Fiber' | ||
import {FIO} from '../main/FIO' | ||
import {Ref} from '../main/Ref' | ||
|
||
/** | ||
* Cancels the provided fiber on exit status. | ||
* Sets the provided ref if two responses have been received. | ||
* @ignore | ||
*/ | ||
export const coordinate = <E1, A1, E2, A2>( | ||
exit: Exit<E1, A1>, | ||
fiber: Fiber<E2, A2>, | ||
ref: Ref<Exit<E1, A1>>, | ||
count: Ref<number>, | ||
await: Await<never, boolean> | ||
) => | ||
ref | ||
.set(exit) | ||
.chain(e => | ||
Exit.isFailure(e) | ||
? fiber.abort.and(await.set(FIO.of(true))) | ||
: count | ||
.update(_ => _ + 1) | ||
.and( | ||
count.read.chain(value => | ||
value === 2 ? await.set(FIO.of(true)) : FIO.of(false) | ||
) | ||
) | ||
) |
This file contains 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
This file contains 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