• 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/implementObjectWorkerExternal.ts
1
// https://github.com/andreashuber69/kiss-worker/blob/develop/README.md
2

3
import type { DedicatedWorker } from "./DedicatedWorker.ts";
4
import type { implementObjectWorker } from "./implementObjectWorker.ts";
5
import type { MethodsOnlyObject } from "./MethodsOnlyObject.ts";
6
import type { ObjectInfo } from "./ObjectInfo.ts";
7
import type { ObjectWorker } from "./ObjectWorker.ts";
8
import { ObjectWorkerImpl } from "./ObjectWorkerImpl.ts";
9
import type { serveObject } from "./serveObject.ts";
10

11
/**
12
 * Creates a factory function returning an object implementing the {@linkcode ObjectWorker} interface.
13
 * @description Compared to {@linkcode implementObjectWorker}, {@linkcode implementObjectWorkerExternal} covers the
14
 * following additional requirements:
15
 * - The factory function returned by {@linkcode implementObjectWorkerExternal} can be executed on **any** thread.
16
 * - The code of the served object is only ever loaded on the worker thread. This can become important when the
17
 * amount of code running on the worker thread is significant, such that you'd rather not load it anywhere else. Build
18
 * tools like [vite](vitejs.dev) support this use case by detecting `new Worker(...)` calls and putting the worker
19
 * script as well as all directly and indirectly called code into a separate chunk. Please see
20
 * [this example](https://github.com/andreashuber69/kiss-worker-demo4) for more information.
21
 * @param createWorker A function that creates a new [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker)
22
 * with every call. This function **must** create a worker running a script different from the one it is created in.
23
 * The script must call {@linkcode serveObject} passing a constructor function and export the type of the object.
24
 * @param _info An instance of {@linkcode ObjectInfo} instantiated with the type exported by the script running on the
25
 * worker thread.
26
 * @returns The factory function returning an object implementing the {@linkcode ObjectWorker} interface.
27
 */
28
export const implementObjectWorkerExternal = <C extends new (..._: never[]) => T, T extends MethodsOnlyObject<T>>(
×
29
    createWorker: () => DedicatedWorker,
30
    _info: ObjectInfo<C, T>,
31
): (...args: ConstructorParameters<C>) => Promise<ObjectWorker<T>> => async (...args: ConstructorParameters<C>) =>
×
32
    await ObjectWorkerImpl.create<C, T>(createWorker, ...args);
×
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