• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

andreashuber69 / kiss-worker / #157

25 Jan 2025 04:20PM UTC coverage: 0.0% (-99.3%) from 99.31%
#157

push

andreashuber69
test: run on compiled files

0 of 33 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 119 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/implementFunctionWorkerExternal.ts
1
// https://github.com/andreashuber69/kiss-worker/blob/develop/README.md
2

3
import type { DedicatedWorker } from "./DedicatedWorker.ts";
4
import type { FunctionInfo } from "./FunctionInfo.ts";
5
import type { FunctionWorker } from "./FunctionWorker.ts";
6
import { FunctionWorkerImpl } from "./FunctionWorkerImpl.ts";
7
import type { implementFunctionWorker } from "./implementFunctionWorker.ts";
8
import type { serveFunction } from "./serveFunction.ts";
9

10
/**
11
 * Creates a factory function returning an object implementing the {@linkcode FunctionWorker} interface.
12
 * @description Compared to {@linkcode implementFunctionWorker}, {@linkcode implementFunctionWorkerExternal} covers the
13
 * following additional requirements:
14
 * - The factory function returned by {@linkcode implementFunctionWorkerExternal} can be executed on **any** thread.
15
 * - The code of the served function is only ever loaded on the worker thread. This can become important when the
16
 * amount of code running on the worker thread is significant, such that you'd rather not load it anywhere else. Build
17
 * tools like [vite](vitejs.dev) support this use case by detecting `new Worker(...)` calls and putting the worker
18
 * script as well as all directly and indirectly called code into a separate chunk. Please see
19
 * [this example](https://github.com/andreashuber69/kiss-worker-demo3) for more information.
20
 * @param createWorker A function that creates a new [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker)
21
 * with every call. This function **must** create a worker running a script different from the one it is created in.
22
 * The script must call {@linkcode serveFunction} passing a function and export the type of said function.
23
 * @param _info An instance of {@linkcode FunctionInfo} instantiated with the type exported by the script running on the
24
 * worker thread.
25
 * @returns The factory function returning an object implementing the {@linkcode FunctionWorker} interface.
26
 */
27
export const implementFunctionWorkerExternal = <T extends (..._: never[]) => unknown>(
×
28
    createWorker: () => DedicatedWorker,
29
    _info: FunctionInfo<T>,
30
): () => FunctionWorker<T> =>
31
    () => new FunctionWorkerImpl<T>(createWorker);
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc