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: add timeout function #250

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MarlonPassos-git
Copy link
Contributor

@MarlonPassos-git MarlonPassos-git commented Sep 18, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

This PR introduces a timeout promise function similar to the delay function, but with the ability to reject upon timeout. It also supports custom error classes passing a function as a parameter.

// Rejects after 1 second with the default "timeout" error message
await _.timeout(1000)

// Rejects after 1 second with a custom error message
await _.timeout(1000, 'Custom timeout message')

// Rejects after 1 second with a custom error object
await _.timeout(1000, () => new Error('Custom error'))

Related issue, if any:

#203

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size 1
A src/async/timeout.ts 163

Footnotes

  1. Function size includes the import dependencies of the function.

@radashi-bot
Copy link

Benchmark Results

Name Current
timeout: with default error message 930.75 ops/sec ±0.83%
timeout: with custom error message 926.11 ops/sec ±0.59%
timeout: with custom error function 919.26 ops/sec ±0.08%

Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure.

@MarlonPassos-git MarlonPassos-git changed the title feat: add timeout feat: add timeout function Sep 18, 2024
@MarlonPassos-git MarlonPassos-git added the new feature This PR adds a new function or extends an existing one label Sep 18, 2024
@aleclarson aleclarson added this to the v12.3.0 milestone Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants