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

feat(delay): Support AbortSignal to delay for improved cancellation #52

Merged
merged 6 commits into from
Jun 15, 2024

Conversation

Hanna922
Copy link
Contributor

Hi👋🏻 I have added the functionality to support cancellation via AbortSignal to the delay, following the debounce.

While working on this, I had a question: Would it be better to create and use a common Error file, Like in undici?

Thank you.

Before

function delay(ms: number): Promise<void>

After

function delay(ms: number, { signal }: DelayOptions = {}): Promise<void>

Copy link

vercel bot commented Jun 14, 2024

@Hanna922 is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (50c3585) to head (0c79258).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #52   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           46        47    +1     
  Lines          223       233   +10     
  Branches        22        25    +3     
=========================================
+ Hits           223       233   +10     

};

signal?.addEventListener('abort', onAbort);
signal?.addEventListener('abort', onAbort, { once: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@raon0211
Copy link
Collaborator

raon0211 commented Jun 15, 2024

As you mentioned, I think making a separate error file would be helpful.

The error's name property has to be AbortError when aborted. (This is a spec of fetch, but it would be better if we follow the spec also in delay.)

// error/AbortError.ts
export class AbortError extends Error {
  constructor (message: string = 'The operation was aborted') {
    super(message);
    this.name = 'AbortError';
  }
}
// function/delay.ts
import { AbortError } from '../../error/AbortError';

/* ... */
return reject(new AbortError());

@Hanna922
Copy link
Contributor Author

@raon0211 I applied a separate error file. c4bbfc8
Thank you for your help 🙇🏻‍♀️

Copy link
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your great contribution!

@raon0211 raon0211 merged commit 8d80869 into toss:main Jun 15, 2024
6 of 7 checks passed
@Hanna922 Hanna922 deleted the feat/delay-abortSignal branch June 15, 2024 06:22
@raon0211
Copy link
Collaborator

#37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants