Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces Streaming #80

Merged
merged 12 commits into from
Jun 13, 2024
Prev Previous commit
Next Next commit
Update return type, rethrow as error as SubstrateError
liamgriffiths committed Jun 7, 2024
commit 505eea2ed5517dcf55faff10df22ccf1e2736870
18 changes: 12 additions & 6 deletions src/Substrate.ts
Original file line number Diff line number Diff line change
@@ -150,10 +150,7 @@ export class Substrate {
/**
* Stream the given nodes, serialized using `Substrate.serialize`.
*/
async streamSerialized(
serialized: any,
endpoint: string = "/compose",
): Promise<any> {
async streamSerialized(serialized: any, endpoint: string = "/compose") {
const url = this.baseUrl + endpoint;
const req = { dag: serialized };
const abortController = new AbortController();
@@ -172,8 +169,17 @@ export class Substrate {
request,
response,
);
} catch (err) {
console.log(err);
} catch (err: unknown) {
if (err instanceof Error) {
if (err.name === "AbortError") {
throw new RequestTimeoutError(
`Request timed out after ${this.timeout}ms`,
);
// TODO: We could propagate timeout errors to nodes too, but I'm
// not sure yet what might be easier for the user to manage.
}
}
throw err;
} finally {
clearTimeout(timeout);
}