@zlink-systems/stream-connector 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,15 +5,20 @@ import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
|
5
5
|
import type { ZlinkStreamFrameSender } from './ZlinkStreamFrameSender';
|
|
6
6
|
import type { ZlinkStreamPendingRequests } from './ZlinkStreamPendingRequests';
|
|
7
7
|
import type { ZlinkStreamReceiveDispatcher } from './ZlinkStreamReceiveDispatcher';
|
|
8
|
+
import type { ZlinkStreamReceivedMessages } from './ZlinkStreamReceivedMessages';
|
|
8
9
|
import type { ZlinkStreamRuntimeMetrics } from './ZlinkStreamRuntimeMetrics';
|
|
9
10
|
export declare class ZlinkStreamConnectorLifecycle {
|
|
10
11
|
private readonly options;
|
|
11
12
|
private readonly pendingRequests;
|
|
12
13
|
private readonly frameSender;
|
|
13
14
|
private readonly receiveDispatcher;
|
|
15
|
+
private readonly receivedMessages;
|
|
14
16
|
private readonly events;
|
|
15
17
|
private readonly metrics;
|
|
16
18
|
private receiveLoopAbort;
|
|
19
|
+
private receiveLoopSleeping;
|
|
20
|
+
private receiveLoopWake;
|
|
21
|
+
private readonly receiveLoopSettled;
|
|
17
22
|
private currentConnection;
|
|
18
23
|
private connectionGeneration;
|
|
19
24
|
private currentState;
|
|
@@ -26,7 +31,7 @@ export declare class ZlinkStreamConnectorLifecycle {
|
|
|
26
31
|
private disconnectedPublished;
|
|
27
32
|
private closeReasonValue?;
|
|
28
33
|
private lateConnectCleanupError;
|
|
29
|
-
constructor(options: RequiredZlinkStreamConnectorOptions, pendingRequests: ZlinkStreamPendingRequests, frameSender: ZlinkStreamFrameSender, receiveDispatcher: ZlinkStreamReceiveDispatcher, events: ZlinkStreamConnectorEvents, metrics: ZlinkStreamRuntimeMetrics);
|
|
34
|
+
constructor(options: RequiredZlinkStreamConnectorOptions, pendingRequests: ZlinkStreamPendingRequests, frameSender: ZlinkStreamFrameSender, receiveDispatcher: ZlinkStreamReceiveDispatcher, receivedMessages: ZlinkStreamReceivedMessages, events: ZlinkStreamConnectorEvents, metrics: ZlinkStreamRuntimeMetrics);
|
|
30
35
|
get isConnected(): boolean;
|
|
31
36
|
get state(): ZlinkStreamConnectionState;
|
|
32
37
|
get closeReason(): ZlinkStreamCloseReason | undefined;
|
|
@@ -35,6 +40,15 @@ export declare class ZlinkStreamConnectorLifecycle {
|
|
|
35
40
|
close(signal?: AbortSignal): Promise<void>;
|
|
36
41
|
serverClosing(reason: ZlinkStreamCloseReason): Promise<void>;
|
|
37
42
|
private closeOnce;
|
|
43
|
+
/**
|
|
44
|
+
* Spec stream-connector 32 §7: `dispatch` runs the callbacks the receive loop
|
|
45
|
+
* queued, it does not drive the transport. Receiving is the receive loop's
|
|
46
|
+
* job in both dispatch modes, which is what lets a `Manual` consumer complete
|
|
47
|
+
* a `waitFor` without pumping, and what keeps this call from blocking on an
|
|
48
|
+
* idle connection. In `Manual` it first lets the loop settle whatever has
|
|
49
|
+
* already arrived, so a packet the transport is holding is delivered by this
|
|
50
|
+
* pump rather than the next one.
|
|
51
|
+
*/
|
|
38
52
|
dispatch(signal?: AbortSignal): Promise<void>;
|
|
39
53
|
connectionForSend(): ZlinkStreamConnection;
|
|
40
54
|
private dispatchAvailable;
|
|
@@ -44,6 +58,9 @@ export declare class ZlinkStreamConnectorLifecycle {
|
|
|
44
58
|
private startReceiveLoop;
|
|
45
59
|
private stopReceiveLoop;
|
|
46
60
|
private runReceiveLoop;
|
|
61
|
+
private sleepUntilWork;
|
|
62
|
+
private settleReceiveLoop;
|
|
63
|
+
private releaseReceiveLoopSettled;
|
|
47
64
|
private shouldContinueReceiveLoop;
|
|
48
65
|
private runHeartbeatTick;
|
|
49
66
|
private disconnectForTransportFailure;
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import { Disposable, ZlinkStreamEncodedPayload, ZlinkStreamMessage } from '../Contracts';
|
|
2
2
|
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
3
3
|
type EncodedMessageHandler = (message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal) => Promise<void> | void;
|
|
4
|
+
/**
|
|
5
|
+
* A wait surface (`waitFor`, `expectNone`, `waitForSequence`) reading the queue
|
|
6
|
+
* directly. It returns true when it consumed the message and must not throw:
|
|
7
|
+
* a failed predicate is reported through the waiting call, not to the queue.
|
|
8
|
+
*/
|
|
9
|
+
type EncodedMessageObserver = (message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>) => boolean;
|
|
4
10
|
export declare class ZlinkStreamReceivedMessages {
|
|
5
11
|
private readonly events;
|
|
12
|
+
private readonly deliverOnArrival;
|
|
6
13
|
private readonly handlers;
|
|
14
|
+
private readonly observers;
|
|
7
15
|
private readonly queue;
|
|
8
16
|
private queueHead;
|
|
9
17
|
private queuedCount;
|
|
10
18
|
private drainTask;
|
|
11
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @param deliverOnArrival `Immediate` runs registered handlers on the receive
|
|
21
|
+
* path; `Manual` leaves them queued until {@link pump} runs them on the
|
|
22
|
+
* caller's thread (spec stream-connector 32 §7). Wait surfaces observe the
|
|
23
|
+
* queue in both modes, so they never depend on this flag.
|
|
24
|
+
*/
|
|
25
|
+
constructor(events: ZlinkStreamConnectorEvents, deliverOnArrival: boolean);
|
|
12
26
|
on(name: string, handler: EncodedMessageHandler): Disposable;
|
|
27
|
+
/**
|
|
28
|
+
* Registers a wait surface over the receive queue. Spec stream-connector 32
|
|
29
|
+
* §7: these are not registered callbacks — they observe and consume the
|
|
30
|
+
* packets the queue has not delivered yet, in both dispatch modes, so
|
|
31
|
+
* `Manual` needs no dispatch pump to complete a wait. The queue is scanned in
|
|
32
|
+
* a microtask so a message that arrived before the wait started is still
|
|
33
|
+
* observed, and so the caller has its subscription in hand by then.
|
|
34
|
+
*/
|
|
35
|
+
observe(name: string, observer: EncodedMessageObserver): Disposable;
|
|
13
36
|
enqueue(message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal): void;
|
|
37
|
+
/**
|
|
38
|
+
* Runs the registered handlers the receive path left queued. `Manual` calls
|
|
39
|
+
* this from `dispatch`; `Immediate` has already drained on arrival.
|
|
40
|
+
*/
|
|
41
|
+
pump(): Promise<void>;
|
|
42
|
+
private offerQueued;
|
|
14
43
|
private scheduleDrain;
|
|
15
44
|
private drain;
|
|
45
|
+
private removeAt;
|
|
16
46
|
private findDeliverableIndex;
|
|
17
47
|
private hasQueuedMessage;
|
|
18
48
|
private advanceHead;
|