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

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

11
/**
12
 * Creates a factory function returning an object implementing the {@linkcode ObjectWorker} interface.
13
 * @description This function covers the simplest use case: A factory function is implemented in a single file, which
14
 * is then imported into code running on the main thread. Please see
15
 * [this example](https://github.com/andreashuber69/kiss-worker-demo2) for more information.
16
 * NOTE: If the returned function needs to be called on other (non-main) threads,
17
 * {@linkcode implementObjectWorkerExternal} must be used to implement it.
18
 * @param createWorker A function that creates a new [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker)
19
 * with every call. This function **must** create a worker running the same script it is created in.
20
 * @param ctor The constructor function for the object that will be served on the worker thread. The worker thread will
21
 * store the object returned by this function and henceforth call the appropriate method on it for each call to one of
22
 * the methods of {@linkcode ObjectWorker.obj}.
23
 * @returns The factory function returning an object implementing the {@linkcode ObjectWorker} interface.
24
 */
25
export const implementObjectWorker = <
×
26
    C extends new (..._: never[]) => T,
27
    T extends MethodsOnlyObject<T> = InstanceType<C>,
28
>(
29
    createWorker: () => DedicatedWorker,
30
    ctor: C,
31
) => {
32
    // Code coverage is not reported for code executed within a worker, because only the original (uninstrumented)
33
    // version of the code is ever loaded.
34
    /* istanbul ignore next -- @preserve */
35
    if (isWorker()) {
36
        serveObject<C, T>(ctor);
37
    }
38

39
    return implementObjectWorkerExternal(createWorker, new ObjectInfo<C, T>());
×
40
};
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