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

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

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

34
    return implementFunctionWorkerExternal(createWorker, new FunctionInfo<T>());
×
35
};
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