Skip to content

fix: unwrap Promise return types in Pool.exec() - #605

Open
AkaashParmar wants to merge 1 commit into
josdejong:masterfrom
AkaashParmar:fix-485-promise-return-type
Open

AkaashParmar wants to merge 1 commit into
josdejong:masterfrom
AkaashParmar:fix-485-promise-return-type

Conversation

@AkaashParmar

Copy link
Copy Markdown

Fix double Promise typing in Pool.exec()

Fixes #485

Problem

The JSDoc return type of Pool.exec() was declared as Promise<ReturnType<T>>.

When a worker function returns a native Promise, such as async function encode(): Promise<Blob>, TypeScript inferred an incorrectly nested Promise type. However, workerpool resolves asynchronous results at runtime before returning them to the caller.

Solution

Updated the return annotation in src/Pool.js to:

Promise<Awaited<ReturnType<T>>>

This correctly unwraps Promise and Promise-like return types while preserving synchronous return types.

Tests

Added compile-time regression tests in test/types/workerpool-tests.ts covering:

  • Synchronous worker functions
  • Async functions returning Promise<Blob>
  • Async functions returning Promise<void>
  • Custom workerpool Promise return types

Validation

  • npm run build:types — Passed
  • npm run test:types — Passed
  • git diff --check — Passed
  • Full test suite — 168 passed, 2 pending, 2 failed.

One worker graceful-exit timeout was reproduced on the clean upstream branch in the same Windows environment. The other timeout has not yet been independently verified against upstream.

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.

exec generic type def doubly wrapped Promise?

2 participants