-
Notifications
You must be signed in to change notification settings - Fork 633
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
feat(async): Add abortable
to async module.
#1939
Conversation
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.
Thanks for your contribution! This seems a reasonable addition to std/async
to me.
LGTM
async/abortable.ts
Outdated
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
import { deferred } from "./deferred.ts"; | ||
|
||
export class AbortedError 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.
I wonder if it makes sense to use DOMException with AbortError instead of this custom error:
new DOMException(reason ? `Aborted: ${reason}` : "Aborted", "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.
Yes i think this would be preferable imo. Ideally it would be using error causes, but DOMException doesnt support that yet (whatwg/webidl#969).
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.
Shall I rewrite it as DOMException
with that?
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.
Shall I rewrite it as DOMException with that?
I think that's more preferable (fetch API rejects with that error, for example). Let's do that
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.
@lambdalisue LGTM!
Hi.
The
abortable
is a wrapper function that makesPromise
andAsyncIterable
cancelable.For example, in the case of
Promise
, it looks like thisand for
AsyncIterable
as followsI hope you all like it.