-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace streamToPromise with Array.fromAsync (#644)
- Loading branch information
1 parent
820037c
commit 26bdf12
Showing
9 changed files
with
65 additions
and
76 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { streamToPromise } from './stream'; | ||
import Array from '@penumbra-zone/polyfills/Array.fromAsync'; | ||
import { AssetsRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
import { viewClient } from '../clients'; | ||
|
||
export const getAllAssets = () => { | ||
const req = new AssetsRequest(); | ||
const iterable = viewClient.assets(req); | ||
return streamToPromise(iterable); | ||
return Array.fromAsync(iterable); | ||
}; |
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { viewClient } from '../clients'; | ||
import { streamToPromise } from './stream'; | ||
import Array from '@penumbra-zone/polyfills/Array.fromAsync'; | ||
import { getUnclaimedSwaps } from '@penumbra-zone/getters'; | ||
import { SwapRecord } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
|
||
export const fetchUnclaimedSwaps = async (): Promise<SwapRecord[]> => { | ||
const responses = await streamToPromise(viewClient.unclaimedSwaps({})); | ||
const responses = await Array.fromAsync(viewClient.unclaimedSwaps({})); | ||
return responses.map(getUnclaimedSwaps); | ||
}; |
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,53 @@ | ||
import { beforeEach, describe, expect, test } from 'vitest'; | ||
|
||
import Array from './Array.fromAsync'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const streamToPromise = Array.fromAsync; | ||
|
||
describe('streamToPromise()', () => { | ||
describe('when one of the streamed items throws', () => { | ||
let error: unknown; | ||
const query = async function* () { | ||
yield* [ | ||
await new Promise(() => { | ||
throw error; | ||
}), | ||
]; | ||
}; | ||
|
||
describe('when the thrown value is an instance of `Error`', () => { | ||
beforeEach(() => { | ||
error = new Error('oops'); | ||
}); | ||
|
||
test('rejects with the error', async () => { | ||
await expect(streamToPromise(query())).rejects.toThrow(error as Error); | ||
}); | ||
}); | ||
|
||
describe('old streamToPromise behavior that Array.fromAsync does not exhibit', () => { | ||
describe('when the thrown value is a string', () => { | ||
beforeEach(() => { | ||
error = 'oops'; | ||
}); | ||
|
||
test.fails("don't reject with the string wrapped in an instance of `Error`", async () => { | ||
await expect(streamToPromise(query())).rejects.toThrow(new Error('oops')); | ||
}); | ||
}); | ||
|
||
describe('when the thrown value is neither an `Error` instance nor a string', () => { | ||
beforeEach(() => { | ||
error = 1n; | ||
}); | ||
|
||
test.fails("don't reject with an unknown error", async () => { | ||
await expect(streamToPromise(query())).rejects.toThrow( | ||
new Error('Unknown error in `streamToPromise`'), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.