-
Notifications
You must be signed in to change notification settings - Fork 0
RAI-10177 add abort signal pollTransaction #83
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
Conversation
| constructor(message?: string) { | ||
| super(message); | ||
|
|
||
| this.name = 'AbortError'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for jumping here, just noticed it.
Why did you decide to extend it and put name? Is there any reason for that?
since as I know error name would be already 'AbortError' when it is aborted. Therefore, I think it doesn't have to be extended.
Here it is from documentation:
https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
The reason why the operation was aborted, which can be any JavaScript value. If not specified, the reason is set to "AbortError"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason is that the error thrown through browser's fetch API is of type DOMException which is different than the one through the node-fetch API, which is explicitly defined as AbortError. Another thing, in the changes here, the abort is not passed to the fetch function, it's only used to break the polling loop and reject the promise manually.
It might be removed if we decided to pass the abort signal to the fetch API, but that requires further changes that should be discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
| } | ||
|
|
||
| export class AbortError extends Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please export it in the entry point.
PR Description
Need to add abort capability for async operations in the SDK to be able to cancel long operations like
pollTransactionfrom the console (See here). The changes adds the abort capability forpollTransactionAPI, by passing anAbortSignalobject reference that can be triggered from outside.