-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rstream): update defWorker() arg types
- add `WorkerSource` type alias - add support for zero-arg fns returning a worker instance - helps v. much with Vite's `xxx?worker` imports - see /examples/mandelbrot for usage
- Loading branch information
1 parent
b2bdd11
commit e07521e
Showing
5 changed files
with
20 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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,9 +1,14 @@ | ||
import { isFunction } from "@thi.ng/checks/is-function"; | ||
import type { WorkerSource } from "./api.js"; | ||
|
||
export const defInlineWorker = (src: string) => | ||
defWorker(new Blob([src], { type: "text/javascript" })); | ||
|
||
export const defWorker = (worker: Worker | string | Blob) => | ||
export const defWorker = (worker: WorkerSource) => | ||
worker instanceof Worker | ||
? worker | ||
: isFunction(worker) | ||
? worker() | ||
: new Worker( | ||
worker instanceof Blob ? URL.createObjectURL(worker) : worker | ||
); |
This file contains 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 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 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