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

snatalenko / node-cqrs / 21717407497

05 Feb 2026 03:26PM UTC coverage: 84.53% (-9.9%) from 94.396%
21717407497

Pull #28

github

web-flow
Merge 025edb883 into 828e39903
Pull Request #28: TypeScript and event dispatching pipeline refactoring

611 of 939 branches covered (65.07%)

819 of 934 new or added lines in 65 files covered. (87.69%)

59 existing lines in 13 files now uncovered.

1213 of 1435 relevant lines covered (84.53%)

28.39 hits per line

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

88.46
/src/workers/utils/createWorker.ts
1
import { Worker } from 'node:worker_threads';
2✔
2
import * as path from 'node:path';
2✔
3
import { isWorkerInitMessage, type IWorkerData } from '../protocol.ts';
2✔
4

5
/**
6
 * Create a worker instance, await a handshake or a failure
7
 *
8
 * @param workerModulePath - Path to worker module
9
 * @param ports - Container with MessagePorts for communication with worker projection and view instances
10
 * @returns Worker instance
11
 */
12
export async function createWorker(workerModulePath: string, ports: IWorkerData) {
2✔
13

14
        const workerEntrypoint = path.isAbsolute(workerModulePath) ?
16!
15
                workerModulePath :
16
                path.resolve(process.cwd(), workerModulePath);
17

18
        const worker = new Worker(workerEntrypoint, {
16✔
19
                workerData: ports,
20
                transferList: [
21
                        ports.projectionPort,
22
                        ports.viewPort
23
                ]
24
        });
25

26
        await new Promise((resolve, reject) => {
16✔
27

28
                const cleanup = () => {
16✔
29
                        // eslint-disable-next-line no-use-before-define
30
                        worker.off('error', onError);
16✔
31
                        // eslint-disable-next-line no-use-before-define
32
                        worker.off('message', onMessage);
16✔
33
                        // eslint-disable-next-line no-use-before-define
34
                        worker.off('exit', onExit);
16✔
35
                };
36

37
                const onMessage = (msg: unknown) => {
16✔
38
                        if (!isWorkerInitMessage(msg))
14!
NEW
39
                                return;
×
40

41
                        cleanup();
14✔
42
                        resolve(undefined);
14✔
43
                };
44

45
                const onError = (err: unknown) => {
16✔
46
                        cleanup();
2✔
47
                        reject(err);
2✔
48
                };
49

50
                const onExit = (exitCode: number) => {
16✔
NEW
51
                        cleanup();
×
NEW
52
                        reject(new Error(`Worker exited prematurely with exit code ${exitCode}`));
×
53
                };
54

55
                worker.on('message', onMessage);
16✔
56
                worker.once('error', onError);
16✔
57
                worker.once('exit', onExit);
16✔
58
        });
59

60
        return worker;
14✔
61
}
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