-
Notifications
You must be signed in to change notification settings - Fork 1
Correct pooled API return types #13
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac26804
fix: expose promise-returning pooled API types
natanelia a7f0092
fix: propagate pooled API types through React
natanelia 3021907
test: assert public pooled API declarations
natanelia 49eaa2e
chore: add pooled API typing changeset
natanelia 7bbbb3d
style: apply Biome formatting
natanelia 7e5bc0d
style: apply Biome formatting
natanelia be7ee6d
fix: reserve then on string-indexed pooled APIs
natanelia 5127afe
test: cover reserved then on string-indexed APIs
natanelia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "comlink-worker-pool": patch | ||
| "comlink-worker-pool-react": patch | ||
| --- | ||
|
|
||
| Correct the public scheduled API types so every pooled method returns a Promise, while reserved `then` and symbol keys are omitted from `getApi()` and the React hook API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,68 @@ | ||
| export * from "./WorkerPool"; | ||
| import { | ||
| WorkerPool as WorkerPoolImplementation, | ||
| type WorkerPoolOptions, | ||
| } from "./WorkerPool"; | ||
|
|
||
| type CallableProxy<TProxy> = { | ||
| // biome-ignore lint/suspicious/noExplicitAny: worker APIs may have arbitrary signatures | ||
| [K in keyof TProxy]: (...args: any[]) => unknown; | ||
| }; | ||
|
|
||
| /** Promise-returning API exposed by WorkerPool.getApi(). */ | ||
| export type PooledApi<TProxy extends CallableProxy<TProxy>> = { | ||
| [K in keyof TProxy as K extends string | ||
| ? K extends "then" | ||
| ? never | ||
| : K | ||
| : never]: TProxy[K] extends (...args: infer TArgs) => infer TResult | ||
| ? (...args: TArgs) => Promise<Awaited<TResult>> | ||
| : never; | ||
| } & { | ||
| /** Reserved so string-indexed APIs cannot make the scheduling proxy thenable. */ | ||
| readonly then?: never; | ||
| }; | ||
|
|
||
| /** Public WorkerPool instance with the scheduled API return type. */ | ||
| export type WorkerPool< | ||
| TProxy extends CallableProxy<TProxy>, | ||
| TTask extends { method: keyof TProxy; args: unknown[] } = { | ||
| method: keyof TProxy; | ||
| args: unknown[]; | ||
| }, | ||
| TResult = Awaited<ReturnType<TProxy[TTask["method"]]>>, | ||
| > = Omit<WorkerPoolImplementation<TProxy, TTask, TResult>, "getApi"> & { | ||
| getApi(): PooledApi<TProxy>; | ||
| }; | ||
|
|
||
| interface WorkerPoolConstructor { | ||
| new < | ||
| TProxy extends CallableProxy<TProxy>, | ||
| TTask extends { method: keyof TProxy; args: unknown[] } = { | ||
| method: keyof TProxy; | ||
| args: unknown[]; | ||
| }, | ||
| TResult = Awaited<ReturnType<TProxy[TTask["method"]]>>, | ||
| >( | ||
| options: WorkerPoolOptions<TProxy>, | ||
| ): WorkerPool<TProxy, TTask, TResult>; | ||
| } | ||
|
|
||
| export const WorkerPool = | ||
| WorkerPoolImplementation as unknown as WorkerPoolConstructor; | ||
|
|
||
| export type { | ||
| QueueOverflowPolicy, | ||
| Task, | ||
| WorkerFactory, | ||
| WorkerPoolEvent, | ||
| WorkerPoolObserver, | ||
| WorkerPoolOptions, | ||
| WorkerPoolShutdownReport, | ||
| WorkerPoolState, | ||
| WorkerPoolStats, | ||
| WorkerPoolTaskOutcome, | ||
| WorkerPoolWorkerRemovalReason, | ||
| WorkerTaskOptions, | ||
| WorkerTerminator, | ||
| } from "./WorkerPool"; | ||
| export * from "./errors"; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.