Skip to content

Commit

Permalink
Fix EitherAsync.mapLeft not awaiting result (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaqqer authored Jun 5, 2023
1 parent 73b65a1 commit 2eab340
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/EitherAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ describe('EitherAsync', () => {
Promise.resolve(0)
).mapLeft((x) => x + 1)

const newEitherAsync3 = EitherAsync.fromPromise(() =>
Promise.resolve(Left(2))
).mapLeft(async (i) => i + 1)

expect(await newEitherAsync.run()).toEqual(Left(1))
expect(await newEitherAsync2.run()).toEqual(Right(0))
expect(await newEitherAsync3.run()).toEqual(Left(3))
})

test('chain', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/EitherAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class EitherAsyncImpl<L, R> implements EitherAsync<L, R> {
try {
return await this.runPromise(helpers as any as EitherAsyncHelpers<L>)
} catch (e: any) {
throw f(e)
throw await f(e)
}
})
}
Expand Down

0 comments on commit 2eab340

Please sign in to comment.