feat: add async option by Uzlopak · Pull Request #371 · tinylibs/tinybench

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for explicitly setting the async option for benchmark tasks in Tinybench. This allows users to override the automatic async detection behavior, which is useful when a function returns a Promise but should be treated as synchronous (e.g., for API compatibility), or vice versa.

Key Changes:

  • Added an optional async boolean field to the FnOptions interface
  • Updated the Task constructor to respect the explicit async option when provided, falling back to automatic detection otherwise
  • Added comprehensive documentation explaining async detection behavior and how to use the new option

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/types.ts Added async optional field to FnOptions interface with documentation
src/task.ts Modified Task constructor to use explicit async option when provided, falling back to isFnAsyncResource()
README.md Added "Async Detection" section with detailed explanation and usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.