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

streetsidesoftware / cspell / 21283815940

23 Jan 2026 10:59AM UTC coverage: 92.838% (+0.01%) from 92.825%
21283815940

Pull #8423

github

web-flow
Merge 74416f189 into 405411fa8
Pull Request #8423: fix: Add NotifyEmitter

8874 of 10620 branches covered (83.56%)

62 of 64 new or added lines in 3 files covered. (96.88%)

4 existing lines in 2 files now uncovered.

17734 of 19102 relevant lines covered (92.84%)

31510.24 hits per line

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

95.24
/packages/cspell-lib/src/rpc/MessagePortEvents.ts
1
import type { MessagePortLike } from './messagePort.js';
2
import type { NotifyEvent } from './notify.js';
3
import { NotifyEmitter } from './notify.js';
4

5
/**
6
 * Wraps a {@link MessagePortLike} and exposes its key events through a
7
 * {@link NotifyEmitter}-based interface.
8
 *
9
 * This class listens to the underlying port's `message`,
10
 * `messageerror`, and `close` events and re-emits them as
11
 * {@link NotifyEvent} instances, making it easier to subscribe to and manage
12
 * notifications from a message port.
13
 */
14
export class MessagePortNotifyEvents {
15
    #notifyMessage: NotifyEmitter<unknown> = new NotifyEmitter();
8✔
16
    #notifyClose: NotifyEmitter<Event> = new NotifyEmitter();
8✔
17
    #notifyMessageError: NotifyEmitter<Error> = new NotifyEmitter();
8✔
18
    #port: MessagePortLike;
19
    #disposed = false;
8✔
20

21
    constructor(port: MessagePortLike) {
22
        this.#port = port;
8✔
23
        this.#port.addListener('message', this.#notifyMessage.notify);
8✔
24
        this.#port.addListener('messageerror', this.#notifyMessageError.notify);
8✔
25
        this.#port.addListener('close', this.#notifyClose.notify);
8✔
26
    }
27

28
    [Symbol.dispose](): void {
29
        if (this.#disposed) return;
10✔
30
        this.#disposed = true;
8✔
31
        this.#port.removeListener('message', this.#notifyMessage.notify);
8✔
32
        this.#port.removeListener('messageerror', this.#notifyMessageError.notify);
8✔
33
        this.#port.removeListener('close', this.#notifyClose.notify);
8✔
34
        this.#notifyMessage[Symbol.dispose]();
8✔
35
        this.#notifyClose[Symbol.dispose]();
8✔
36
        this.#notifyMessageError[Symbol.dispose]();
8✔
37
    }
38

39
    /**
40
     * Register a handler to called when a message is received.
41
     */
42
    get onMessage(): NotifyEvent<unknown> {
43
        return this.#notifyMessage.onEvent;
3✔
44
    }
45

46
    /**
47
     * Return a Promise that resolves on the next message.
48
     * @param signal - A signal to abort the wait.
49
     * @returns A Promise that resolves with the next message received.
50
     */
51
    readonly awaitNextMessage = (signal?: AbortSignal): Promise<unknown> => this.#notifyMessage.awaitNext(signal);
8✔
52

53
    /**
54
     * Return a Promise that resolves on the close event.
55
     * @param signal - A signal to abort the wait.
56
     * @returns A Promise that resolves when the port is closed.
57
     */
58
    readonly awaitClose = (signal?: AbortSignal): Promise<unknown> => this.#notifyClose.awaitNext(signal);
8✔
59

60
    /**
61
     * Register a handler to called when the port is closed.
62
     */
63
    get onClose(): NotifyEvent<Event> {
64
        return this.#notifyClose.onEvent;
2✔
65
    }
66

67
    /**
68
     * Register a handler to called when a message error is received.
69
     */
70
    get onMessageError(): NotifyEvent<Error> {
NEW
71
        return this.#notifyMessageError.onEvent;
×
72
    }
73
}
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