@zlink-systems/framework 0.29.1 → 0.30.1
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.
- package/LICENSE +150 -68
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
- package/dist/contracts/Channels/Calls.d.ts +2 -1
- package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
- package/dist/contracts/Configuration/Builders.d.ts +1 -2
- package/dist/contracts/Configuration/Configs.d.ts +0 -5
- package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
- package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
- package/dist/contracts/Configuration/index.d.ts +1 -1
- package/dist/contracts/Handlers/Attributes.d.ts +5 -13
- package/dist/contracts/Handlers/Attributes.js +7 -11
- package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
- package/dist/contracts/Handlers/JsonContract.js +4 -153
- package/dist/contracts/Spots/Contracts.d.ts +2 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -1
- package/dist/nest-integration.d.ts +1 -1
- package/dist/nest-integration.js +2 -1
- package/dist/runtime/actors/actor-client.d.ts +1 -1
- package/dist/runtime/actors/actor-client.js +14 -12
- package/dist/runtime/actors/actor-handoff.d.ts +3 -2
- package/dist/runtime/actors/actor-handoff.js +15 -7
- package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
- package/dist/runtime/actors/actor-local-native-join.js +9 -12
- package/dist/runtime/actors/actor-remote-wire.js +15 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
- package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
- package/dist/runtime/actors/index.d.ts +2 -1
- package/dist/runtime/actors/index.js +18 -6
- package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
- package/dist/runtime/admission.d.ts +1 -1
- package/dist/runtime/admission.js +15 -5
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
- package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
- package/dist/runtime/application-jobs/contracts.d.ts +15 -2
- package/dist/runtime/backend/contracts/index.d.ts +27 -27
- package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
- package/dist/runtime/backend/mesh-completion-table.js +160 -50
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
- package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
- package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
- package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
- package/dist/runtime/backend/runtime-message.d.ts +1 -0
- package/dist/runtime/backend/runtime-message.js +5 -0
- package/dist/runtime/backend/runtime-values.d.ts +1 -0
- package/dist/runtime/backend/runtime-values.js +2 -1
- package/dist/runtime/channels/channel-clients.d.ts +1 -0
- package/dist/runtime/channels/channel-clients.js +58 -21
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
- package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
- package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
- package/dist/runtime/channels/channel-dispatch-services.js +45 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
- package/dist/runtime/channels/channel-dispatchers.js +27 -26
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
- package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
- package/dist/runtime/channels/channel-envelope.d.ts +1 -0
- package/dist/runtime/channels/channel-envelope.js +83 -8
- package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
- package/dist/runtime/channels/channel-outbound-operations.js +8 -8
- package/dist/runtime/channels/channel-receive-loops.js +3 -3
- package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
- package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
- package/dist/runtime/channels/channel-runtime-manager.js +12 -12
- package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
- package/dist/runtime/channels/channel-socket-registry.js +59 -82
- package/dist/runtime/channels/channel-transports.d.ts +18 -15
- package/dist/runtime/channels/channel-transports.js +48 -31
- package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
- package/dist/runtime/channels/local-spot-route-transport.js +2 -1
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
- package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
- package/dist/runtime/channels/source-spot-router.d.ts +2 -2
- package/dist/runtime/channels/source-spot-router.js +4 -4
- package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-node-route-transport.js +4 -4
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
- package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow.js +3 -3
- package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
- package/dist/runtime/execution/serial-execution-queue.js +1 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
- package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
- package/dist/runtime/foundation/durable-service-request.js +98 -0
- package/dist/runtime/foundation/operation-identity.d.ts +1 -0
- package/dist/runtime/foundation/operation-identity.js +5 -1
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
- package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
- package/dist/runtime/foundation/service-liveness-registry.js +57 -44
- package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
- package/dist/runtime/foundation/service-mailbox.js +2 -1
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
- package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
- package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
- package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
- package/dist/runtime/foundation/service-topology-registry.js +69 -30
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
- package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
- package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
- package/dist/runtime/handlers/handler-instance-scope.js +54 -11
- package/dist/runtime/host/actor-packet-relay.js +7 -7
- package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
- package/dist/runtime/host/application-job-queue.d.ts +28 -9
- package/dist/runtime/host/application-job-queue.js +214 -50
- package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
- package/dist/runtime/host/entry-actor-runtime.js +4 -1
- package/dist/runtime/host/index.d.ts +7 -1
- package/dist/runtime/host/index.js +154 -126
- package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
- package/dist/runtime/host/instance-activation-authority.js +89 -25
- package/dist/runtime/host/remote-bound-session-relay.js +2 -18
- package/dist/runtime/host/route-mesh-runtime.js +1 -1
- package/dist/runtime/host/service-relocation-control.d.ts +1 -0
- package/dist/runtime/host/service-relocation-control.js +10 -4
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
- package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
- package/dist/runtime/host/spot-address-transport.d.ts +1 -0
- package/dist/runtime/host/spot-address-transport.js +28 -14
- package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
- package/dist/runtime/locations/actor-location-claims.js +34 -19
- package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
- package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
- package/dist/runtime/locations/in-memory-authority-store.js +80 -8
- package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
- package/dist/runtime/locations/in-memory-location-store.js +19 -3
- package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
- package/dist/runtime/locations/lifecycle.d.ts +1 -2
- package/dist/runtime/locations/lifecycle.js +2 -5
- package/dist/runtime/locations/location-store-repository.d.ts +3 -2
- package/dist/runtime/locations/location-store-repository.js +165 -22
- package/dist/runtime/locations/resolvers.d.ts +2 -1
- package/dist/runtime/locations/resolvers.js +10 -1
- package/dist/runtime/locations/runtime.d.ts +1 -1
- package/dist/runtime/locations/runtime.js +24 -23
- package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
- package/dist/runtime/messaging/framework-json-v1.js +38 -294
- package/dist/runtime/messaging/packet-name.d.ts +1 -1
- package/dist/runtime/messaging/packet-name.js +8 -24
- package/dist/runtime/messaging/request-result.d.ts +2 -0
- package/dist/runtime/messaging/request-result.js +54 -0
- package/dist/runtime/messaging/submission-result.d.ts +2 -1
- package/dist/runtime/messaging/submission-result.js +7 -4
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
- package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
- package/dist/runtime/spots/index.d.ts +7 -3
- package/dist/runtime/spots/index.js +23 -16
- package/dist/runtime/spots/spot-activation.d.ts +3 -1
- package/dist/runtime/spots/spot-activation.js +21 -12
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
- package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
- package/dist/runtime/spots/spot-entry-activation.js +9 -3
- package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
- package/dist/runtime/spots/spot-handler-registry.js +18 -8
- package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
- package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
- package/dist/runtime/spots/spot-outbound.d.ts +3 -0
- package/dist/runtime/spots/spot-outbound.js +24 -15
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
- package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
- package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
- package/dist/runtime/spots/spot-timer.js +1 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
- package/dist/runtime/streams/stream-session-runtime.js +14 -28
- package/package.json +3 -3
- package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
- package/src/contracts/Channels/Calls.ts +2 -1
- package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
- package/src/contracts/Configuration/Builders.ts +1 -2
- package/src/contracts/Configuration/Configs.ts +0 -6
- package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
- package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
- package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
- package/src/contracts/Configuration/index.ts +1 -6
- package/src/contracts/Handlers/Attributes.ts +14 -21
- package/src/contracts/Handlers/JsonContract.ts +8 -216
- package/src/contracts/Spots/Contracts.ts +2 -1
- package/src/internal.ts +1 -0
- package/src/nest-integration.ts +1 -0
- package/src/runtime/actors/actor-client.ts +40 -16
- package/src/runtime/actors/actor-handoff.ts +22 -8
- package/src/runtime/actors/actor-join-relocation.ts +1 -0
- package/src/runtime/actors/actor-local-native-join.ts +17 -26
- package/src/runtime/actors/actor-remote-wire.ts +17 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
- package/src/runtime/actors/actor-routed-json-request.ts +10 -2
- package/src/runtime/actors/index.ts +19 -5
- package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
- package/src/runtime/admission.ts +18 -5
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
- package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
- package/src/runtime/application-jobs/contracts.ts +28 -2
- package/src/runtime/backend/contracts/index.ts +63 -32
- package/src/runtime/backend/mesh-completion-table.ts +175 -59
- package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
- package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
- package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
- package/src/runtime/backend/raw-binding-port.ts +18 -3
- package/src/runtime/backend/runtime-message.ts +6 -0
- package/src/runtime/backend/runtime-values.ts +1 -0
- package/src/runtime/channels/channel-clients.ts +90 -41
- package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
- package/src/runtime/channels/channel-dispatch-services.ts +69 -1
- package/src/runtime/channels/channel-dispatchers.ts +29 -27
- package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
- package/src/runtime/channels/channel-envelope.ts +133 -8
- package/src/runtime/channels/channel-outbound-operations.ts +22 -8
- package/src/runtime/channels/channel-receive-loops.ts +3 -3
- package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
- package/src/runtime/channels/channel-runtime-manager.ts +29 -12
- package/src/runtime/channels/channel-socket-registry.ts +84 -130
- package/src/runtime/channels/channel-transports.ts +128 -60
- package/src/runtime/channels/local-spot-route-transport.ts +3 -1
- package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
- package/src/runtime/channels/source-spot-router.ts +8 -4
- package/src/runtime/channels/spot-node-route-transport.ts +8 -4
- package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
- package/src/runtime/diagnostics/message-flow.ts +1 -1
- package/src/runtime/execution/serial-execution-queue.ts +2 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
- package/src/runtime/foundation/durable-service-request.ts +137 -0
- package/src/runtime/foundation/operation-identity.ts +5 -1
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
- package/src/runtime/foundation/service-liveness-registry.ts +68 -59
- package/src/runtime/foundation/service-mailbox.ts +7 -1
- package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
- package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
- package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
- package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
- package/src/runtime/foundation/service-topology-registry.ts +103 -42
- package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
- package/src/runtime/handlers/handler-instance-scope.ts +67 -16
- package/src/runtime/host/actor-packet-relay.ts +7 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
- package/src/runtime/host/application-job-queue.ts +249 -48
- package/src/runtime/host/entry-actor-runtime.ts +5 -0
- package/src/runtime/host/index.ts +224 -160
- package/src/runtime/host/instance-activation-authority.ts +132 -27
- package/src/runtime/host/remote-bound-session-relay.ts +2 -23
- package/src/runtime/host/route-mesh-runtime.ts +1 -1
- package/src/runtime/host/service-relocation-control.ts +11 -5
- package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
- package/src/runtime/host/spot-address-transport.ts +49 -24
- package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
- package/src/runtime/locations/actor-location-claims.ts +52 -30
- package/src/runtime/locations/domain-store-contract.ts +6 -2
- package/src/runtime/locations/in-memory-authority-store.ts +113 -9
- package/src/runtime/locations/in-memory-location-store.ts +25 -3
- package/src/runtime/locations/internal-location-contracts.ts +4 -0
- package/src/runtime/locations/lifecycle.ts +8 -26
- package/src/runtime/locations/location-store-repository.ts +220 -15
- package/src/runtime/locations/resolvers.ts +25 -2
- package/src/runtime/locations/runtime.ts +28 -24
- package/src/runtime/messaging/framework-json-v1.ts +5 -325
- package/src/runtime/messaging/packet-name.ts +5 -25
- package/src/runtime/messaging/request-result.ts +58 -0
- package/src/runtime/messaging/submission-result.ts +7 -3
- package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
- package/src/runtime/spots/index.ts +30 -2
- package/src/runtime/spots/spot-activation.ts +33 -10
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
- package/src/runtime/spots/spot-entry-activation.ts +12 -2
- package/src/runtime/spots/spot-handler-registry.ts +41 -8
- package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
- package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
- package/src/runtime/spots/spot-outbound.ts +36 -16
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
- package/src/runtime/spots/spot-routing-internal.ts +14 -0
- package/src/runtime/spots/spot-runtime-ports.ts +3 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
- package/src/runtime/spots/spot-timer.ts +5 -1
- package/src/runtime/streams/stream-session-runtime.ts +13 -30
|
@@ -4,18 +4,114 @@ exports.ZLinkMeshCompletionTable = void 0;
|
|
|
4
4
|
exports.closeMeshCompletion = closeMeshCompletion;
|
|
5
5
|
const runtime_message_1 = require("./runtime-message");
|
|
6
6
|
const operation_identity_1 = require("../foundation/operation-identity");
|
|
7
|
+
const COMPLETION_SLOT_BLOCK_SIZE = 64;
|
|
8
|
+
const COMPLETION_HASH_BUCKETS_PER_SLOT = 2;
|
|
9
|
+
const COMPLETION_HASH_WORD_SCALE = 0x1_0000;
|
|
10
|
+
const COMPLETION_HASH_MULTIPLIER = 0x9e37_79b1;
|
|
11
|
+
const COMPLETION_ABORT_OPTIONS = Object.freeze({ once: true });
|
|
12
|
+
class CompletionSlot {
|
|
13
|
+
abort;
|
|
14
|
+
generation = 0;
|
|
15
|
+
next = -1;
|
|
16
|
+
high;
|
|
17
|
+
low;
|
|
18
|
+
hashNext = -1;
|
|
19
|
+
resolve;
|
|
20
|
+
reject;
|
|
21
|
+
signal;
|
|
22
|
+
constructor(abort) {
|
|
23
|
+
this.abort = abort;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
class ZLinkMeshCompletionTable {
|
|
8
27
|
onDiagnostic;
|
|
9
|
-
|
|
28
|
+
buckets = new Int32Array(0);
|
|
29
|
+
slots = [];
|
|
30
|
+
free = -1;
|
|
31
|
+
activeCount = 0;
|
|
10
32
|
disposed = false;
|
|
11
33
|
constructor(onDiagnostic) {
|
|
12
34
|
this.onDiagnostic = onDiagnostic;
|
|
35
|
+
this.prepareSlots();
|
|
36
|
+
}
|
|
37
|
+
prepareSlots() {
|
|
38
|
+
const start = this.slots.length;
|
|
39
|
+
for (let index = start; index < start + COMPLETION_SLOT_BLOCK_SIZE; index++) {
|
|
40
|
+
const slot = new CompletionSlot(() => {
|
|
41
|
+
const reject = slot.reject;
|
|
42
|
+
const signal = slot.signal;
|
|
43
|
+
if (reject === undefined)
|
|
44
|
+
return;
|
|
45
|
+
this.releaseSlot(index);
|
|
46
|
+
reject(signal?.reason ?? new DOMException('The operation was aborted.', 'AbortError'));
|
|
47
|
+
});
|
|
48
|
+
slot.next = this.free;
|
|
49
|
+
this.slots.push(slot);
|
|
50
|
+
this.free = index;
|
|
51
|
+
}
|
|
52
|
+
const minimumBuckets = this.slots.length * COMPLETION_HASH_BUCKETS_PER_SLOT;
|
|
53
|
+
this.buckets = new Int32Array(2 ** Math.ceil(Math.log2(minimumBuckets))).fill(-1);
|
|
54
|
+
for (let index = 0; index < this.slots.length; index++) {
|
|
55
|
+
const slot = this.slots[index];
|
|
56
|
+
if (slot.high === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
this.indexSlot(index);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
bucket(high, low) {
|
|
62
|
+
const highWord = Number(high);
|
|
63
|
+
const lowWord = Number(low);
|
|
64
|
+
// Bucket selection may collide; the stored 128-bit identity is compared exactly.
|
|
65
|
+
const hash = Math.imul(highWord ^ Math.trunc(highWord / COMPLETION_HASH_WORD_SCALE), COMPLETION_HASH_MULTIPLIER) ^
|
|
66
|
+
lowWord ^
|
|
67
|
+
Math.trunc(lowWord / COMPLETION_HASH_WORD_SCALE);
|
|
68
|
+
return hash & (this.buckets.length - 1);
|
|
69
|
+
}
|
|
70
|
+
indexSlot(index) {
|
|
71
|
+
const slot = this.slots[index];
|
|
72
|
+
const bucket = this.bucket(slot.high, slot.low);
|
|
73
|
+
slot.hashNext = this.buckets[bucket];
|
|
74
|
+
this.buckets[bucket] = index;
|
|
75
|
+
}
|
|
76
|
+
findSlot(operationId) {
|
|
77
|
+
(0, operation_identity_1.validateOperationIdentity)(operationId);
|
|
78
|
+
for (let index = this.buckets[this.bucket(operationId.high, operationId.low)]; index !== -1; index = this.slots[index].hashNext) {
|
|
79
|
+
const slot = this.slots[index];
|
|
80
|
+
if (slot.high === operationId.high && slot.low === operationId.low)
|
|
81
|
+
return index;
|
|
82
|
+
}
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
releaseSlot(index) {
|
|
86
|
+
const slot = this.slots[index];
|
|
87
|
+
if (slot.high !== undefined) {
|
|
88
|
+
const bucket = this.bucket(slot.high, slot.low);
|
|
89
|
+
let previous = -1;
|
|
90
|
+
let current = this.buckets[bucket];
|
|
91
|
+
while (current !== index) {
|
|
92
|
+
previous = current;
|
|
93
|
+
current = this.slots[current].hashNext;
|
|
94
|
+
}
|
|
95
|
+
if (previous === -1)
|
|
96
|
+
this.buckets[bucket] = slot.hashNext;
|
|
97
|
+
else
|
|
98
|
+
this.slots[previous].hashNext = slot.hashNext;
|
|
99
|
+
}
|
|
100
|
+
slot.signal?.removeEventListener('abort', slot.abort);
|
|
101
|
+
slot.high = undefined;
|
|
102
|
+
slot.low = undefined;
|
|
103
|
+
slot.hashNext = -1;
|
|
104
|
+
slot.signal = undefined;
|
|
105
|
+
slot.resolve = undefined;
|
|
106
|
+
slot.reject = undefined;
|
|
107
|
+
slot.next = this.free;
|
|
108
|
+
this.free = index;
|
|
109
|
+
this.activeCount--;
|
|
13
110
|
}
|
|
14
111
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* arrived before their waiter.
|
|
112
|
+
* Reserves the dispatcher slot before transport submission. The backend
|
|
113
|
+
* observes native terminals through Promises, so identity binding finishes
|
|
114
|
+
* before the terminal callback can run, without an infrastructure pump.
|
|
19
115
|
*/
|
|
20
116
|
submit(operation, signal) {
|
|
21
117
|
if (this.isDisposed()) {
|
|
@@ -24,40 +120,43 @@ class ZLinkMeshCompletionTable {
|
|
|
24
120
|
if (signal?.aborted === true) {
|
|
25
121
|
return Promise.reject(signal.reason ?? new DOMException('The operation was aborted.', 'AbortError'));
|
|
26
122
|
}
|
|
27
|
-
const operationId = operation();
|
|
28
|
-
// The backend submission callback can synchronously re-enter `dispose()`.
|
|
29
|
-
// TypeScript's control-flow analysis cannot observe mutation through it.
|
|
30
|
-
if (this.disposed) {
|
|
31
|
-
return Promise.reject(new Error('Mesh completion table is disposed.'));
|
|
32
|
-
}
|
|
33
|
-
const key = (0, operation_identity_1.operationIdentityKey)(operationId);
|
|
34
|
-
if (this.pending.has(key)) {
|
|
35
|
-
return Promise.reject(new Error(`Mesh operation '${key}' is already pending.`));
|
|
36
|
-
}
|
|
37
123
|
return new Promise((resolve, reject) => {
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
124
|
+
if (this.free === -1)
|
|
125
|
+
this.prepareSlots();
|
|
126
|
+
const index = this.free;
|
|
127
|
+
const slot = this.slots[index];
|
|
128
|
+
this.free = slot.next;
|
|
129
|
+
const generation = ++slot.generation;
|
|
130
|
+
slot.resolve = resolve;
|
|
131
|
+
slot.reject = reject;
|
|
132
|
+
slot.signal = signal;
|
|
133
|
+
this.activeCount++;
|
|
134
|
+
try {
|
|
135
|
+
signal?.addEventListener('abort', slot.abort, COMPLETION_ABORT_OPTIONS);
|
|
136
|
+
const operationId = operation();
|
|
137
|
+
// A reentrant abort may release and reuse this slot during submission.
|
|
138
|
+
if (slot.generation !== generation || slot.resolve !== resolve)
|
|
139
|
+
return;
|
|
140
|
+
if (this.findSlot(operationId) !== -1) {
|
|
141
|
+
throw new Error(`Mesh operation '${(0, operation_identity_1.operationIdentityKey)(operationId)}' is already pending.`);
|
|
142
|
+
}
|
|
143
|
+
slot.high = operationId.high;
|
|
144
|
+
slot.low = operationId.low;
|
|
145
|
+
this.indexSlot(index);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (slot.generation === generation && slot.resolve === resolve)
|
|
149
|
+
this.releaseSlot(index);
|
|
150
|
+
reject(error);
|
|
45
151
|
}
|
|
46
|
-
signal?.addEventListener('abort', abort, { once: true });
|
|
47
|
-
this.pending.set(key, {
|
|
48
|
-
resolve,
|
|
49
|
-
reject,
|
|
50
|
-
removeAbort: signal === undefined ? undefined : () => signal.removeEventListener('abort', abort)
|
|
51
|
-
});
|
|
52
152
|
});
|
|
53
153
|
}
|
|
54
154
|
isDisposed() {
|
|
55
155
|
return this.disposed;
|
|
56
156
|
}
|
|
57
|
-
complete(record) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
if (pending === undefined) {
|
|
157
|
+
complete(record, materialize) {
|
|
158
|
+
const index = this.findSlot(record.operationId);
|
|
159
|
+
if (index === -1) {
|
|
61
160
|
this.onDiagnostic?.({
|
|
62
161
|
kind: 'unknownOrLate',
|
|
63
162
|
operationId: Object.freeze({ ...record.operationId }),
|
|
@@ -65,13 +164,15 @@ class ZLinkMeshCompletionTable {
|
|
|
65
164
|
});
|
|
66
165
|
return;
|
|
67
166
|
}
|
|
68
|
-
this.
|
|
69
|
-
|
|
167
|
+
const slot = this.slots[index];
|
|
168
|
+
const resolve = slot.resolve;
|
|
169
|
+
const reject = slot.reject;
|
|
170
|
+
this.releaseSlot(index);
|
|
70
171
|
try {
|
|
71
|
-
|
|
172
|
+
resolve(retainCompletion(materialize === undefined ? record : materialize()));
|
|
72
173
|
}
|
|
73
174
|
catch (error) {
|
|
74
|
-
|
|
175
|
+
reject(error);
|
|
75
176
|
}
|
|
76
177
|
}
|
|
77
178
|
dispose(reason = new Error('Mesh completion table is disposed.')) {
|
|
@@ -79,34 +180,43 @@ class ZLinkMeshCompletionTable {
|
|
|
79
180
|
return;
|
|
80
181
|
}
|
|
81
182
|
this.disposed = true;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
entry.reject(reason);
|
|
183
|
+
for (let index = 0; index < this.slots.length; index++) {
|
|
184
|
+
const reject = this.slots[index].reject;
|
|
185
|
+
if (reject === undefined)
|
|
186
|
+
continue;
|
|
187
|
+
this.releaseSlot(index);
|
|
188
|
+
reject(reason);
|
|
89
189
|
}
|
|
90
190
|
}
|
|
91
191
|
get pendingCount() {
|
|
92
|
-
return this.
|
|
192
|
+
return this.activeCount;
|
|
93
193
|
}
|
|
94
194
|
}
|
|
95
195
|
exports.ZLinkMeshCompletionTable = ZLinkMeshCompletionTable;
|
|
96
196
|
function retainCompletion(record) {
|
|
197
|
+
const parts = retainCompletionParts(record.parts);
|
|
198
|
+
// The retention pass verifies every part is already a managed runtime message.
|
|
199
|
+
if (parts === record.parts)
|
|
200
|
+
return record;
|
|
97
201
|
return {
|
|
98
202
|
terminalResult: record.terminalResult,
|
|
99
203
|
failureErrno: record.failureErrno,
|
|
100
204
|
operationKind: record.operationKind,
|
|
101
205
|
kindData: record.kindData,
|
|
102
|
-
parts
|
|
206
|
+
parts
|
|
103
207
|
};
|
|
104
208
|
}
|
|
105
|
-
function
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
209
|
+
function retainCompletionParts(parts) {
|
|
210
|
+
// Reuse managed messages and wrap binding payloads in the runtime representation.
|
|
211
|
+
let retained;
|
|
212
|
+
for (let index = 0; index < parts.length; index++) {
|
|
213
|
+
const part = parts[index];
|
|
214
|
+
if (!(part instanceof runtime_message_1.ZLinkBufferMessage)) {
|
|
215
|
+
retained ??= parts.slice();
|
|
216
|
+
retained[index] = runtime_message_1.ZLinkBufferMessage.fromOwned(runtime_message_1.ZLinkBufferMessage.retainPayload(part));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return retained ?? parts;
|
|
110
220
|
}
|
|
111
221
|
function closeMeshCompletion(completion) {
|
|
112
222
|
closeParts(completion.parts);
|
|
@@ -20,6 +20,7 @@ export interface ZLinkMeshDispatchFailureContext {
|
|
|
20
20
|
export declare class ZLinkMeshDispatchPump {
|
|
21
21
|
private readonly node;
|
|
22
22
|
private readonly options;
|
|
23
|
+
private readonly dispatchOwnedRecord;
|
|
23
24
|
private pendingDomains;
|
|
24
25
|
private infrastructureScheduled;
|
|
25
26
|
private disposed;
|
|
@@ -37,6 +38,8 @@ export declare class ZLinkMeshDispatchPump {
|
|
|
37
38
|
private startApplicationWorker;
|
|
38
39
|
private runApplicationWorker;
|
|
39
40
|
private waitForApplicationReady;
|
|
41
|
+
private dispatchRecord;
|
|
42
|
+
private finishRecord;
|
|
40
43
|
private reportDispatchError;
|
|
41
44
|
/**
|
|
42
45
|
* Infrastructure controls must not wait for an application permit. During
|
|
@@ -24,6 +24,7 @@ const detachedMeshDispatchScope = node_async_hooks_1.AsyncLocalStorage.snapshot(
|
|
|
24
24
|
class ZLinkMeshDispatchPump {
|
|
25
25
|
node;
|
|
26
26
|
options;
|
|
27
|
+
dispatchOwnedRecord = this.dispatchRecord.bind(this);
|
|
27
28
|
pendingDomains = service_runtime_contracts_1.ReadyDomain.None;
|
|
28
29
|
infrastructureScheduled = false;
|
|
29
30
|
disposed = false;
|
|
@@ -140,6 +141,31 @@ class ZLinkMeshDispatchPump {
|
|
|
140
141
|
}
|
|
141
142
|
return new Promise((resolve) => this.idleApplicationWorkers.add(resolve));
|
|
142
143
|
}
|
|
144
|
+
dispatchRecord(owner, record) {
|
|
145
|
+
let result;
|
|
146
|
+
try {
|
|
147
|
+
result = this.options.dispatch(owner, record);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
return result === undefined
|
|
154
|
+
? this.finishRecord(record)
|
|
155
|
+
: Promise.resolve(result).then(() => this.finishRecord(record), (error) => this.reportDispatchError(error, meshDispatchFailureContext(record)));
|
|
156
|
+
}
|
|
157
|
+
finishRecord(record) {
|
|
158
|
+
let result;
|
|
159
|
+
try {
|
|
160
|
+
result = record.onTerminalCompletion?.();
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (result !== undefined)
|
|
167
|
+
return Promise.resolve(result).catch((error) => this.reportDispatchError(error, meshDispatchFailureContext(record)));
|
|
168
|
+
}
|
|
143
169
|
reportDispatchError(error, context) {
|
|
144
170
|
this.options.reportError?.(error, context);
|
|
145
171
|
}
|
|
@@ -192,7 +218,7 @@ class ZLinkMeshDispatchPump {
|
|
|
192
218
|
async drainDomain(domain, readyBatch, receiveBatch, claimBudget) {
|
|
193
219
|
let claimsDrained = 0;
|
|
194
220
|
try {
|
|
195
|
-
|
|
221
|
+
while (!this.disposed) {
|
|
196
222
|
if (claimBudget !== undefined && claimsDrained >= claimBudget) {
|
|
197
223
|
// Lifecycle work has priority, but a bounded turn lets application
|
|
198
224
|
// work make progress when lifecycle records keep arriving.
|
|
@@ -217,20 +243,18 @@ class ZLinkMeshDispatchPump {
|
|
|
217
243
|
try {
|
|
218
244
|
ownerReceiveBatch ??= this.node.createReceiveBatch(MESH_DISPATCH_RECEIVE_CAPACITY, this.options.partCapacity ?? DEFAULT_MESH_PART_CAPACITY);
|
|
219
245
|
const capacity = owner.ordinaryIngressPreAdmitted === true ? MESH_DISPATCH_RECEIVE_CAPACITY : 1;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
break;
|
|
233
|
-
// This owner keeps its claim while it drains, so its records stay in FIFO order.
|
|
246
|
+
let claimPermit = owner.terminalCompletion === true ||
|
|
247
|
+
owner.ordinaryIngressPreAdmitted === true ||
|
|
248
|
+
domain === service_runtime_contracts_1.ReadyDomain.Infrastructure
|
|
249
|
+
? undefined
|
|
250
|
+
: await this.acquirePermit();
|
|
251
|
+
try {
|
|
252
|
+
if (this.capacityStop.signal.aborted)
|
|
253
|
+
return;
|
|
254
|
+
ownerReceiveBatch.reset(capacity);
|
|
255
|
+
const received = claim.recvBatch(ownerReceiveBatch, runtime_values_1.ZLINK_BACKEND_RECV_DONT_WAIT);
|
|
256
|
+
if (received.ok) {
|
|
257
|
+
// The bounded batch stays in claim order until its records finish.
|
|
234
258
|
try {
|
|
235
259
|
for (const record of received.records) {
|
|
236
260
|
if (this.disposed)
|
|
@@ -240,17 +264,10 @@ class ZLinkMeshDispatchPump {
|
|
|
240
264
|
throw new Error('Pre-admitted raw ingress record lost its Application Job Queue permit.');
|
|
241
265
|
}
|
|
242
266
|
this.recordsSinceYield += 1;
|
|
243
|
-
const dispatch = async () => {
|
|
244
|
-
try {
|
|
245
|
-
await this.options.dispatch(owner, record);
|
|
246
|
-
await record.onTerminalCompletion?.();
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
267
|
if (permit === undefined) {
|
|
253
|
-
|
|
268
|
+
const dispatched = this.dispatchRecord(owner, record);
|
|
269
|
+
if (dispatched !== undefined)
|
|
270
|
+
await dispatched;
|
|
254
271
|
}
|
|
255
272
|
else {
|
|
256
273
|
if (domain === service_runtime_contracts_1.ReadyDomain.Application &&
|
|
@@ -261,11 +278,10 @@ class ZLinkMeshDispatchPump {
|
|
|
261
278
|
// owned by the receive attempt's finally block.
|
|
262
279
|
if (permit === claimPermit)
|
|
263
280
|
claimPermit = undefined;
|
|
264
|
-
|
|
281
|
+
const dispatched = (0, application_job_queue_scope_1.runWithApplicationJobPermit)(permit, this.dispatchOwnedRecord, owner, record);
|
|
282
|
+
if (dispatched !== undefined)
|
|
283
|
+
await dispatched;
|
|
265
284
|
}
|
|
266
|
-
const yieldTurn = this.yieldIfNeeded();
|
|
267
|
-
if (yieldTurn !== undefined)
|
|
268
|
-
await yieldTurn;
|
|
269
285
|
}
|
|
270
286
|
}
|
|
271
287
|
finally {
|
|
@@ -278,9 +294,9 @@ class ZLinkMeshDispatchPump {
|
|
|
278
294
|
}
|
|
279
295
|
}
|
|
280
296
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
claimPermit?.releaseAfterInternalProcessing();
|
|
284
300
|
}
|
|
285
301
|
}
|
|
286
302
|
finally {
|
|
@@ -288,6 +304,9 @@ class ZLinkMeshDispatchPump {
|
|
|
288
304
|
if (receiveBatch === undefined)
|
|
289
305
|
ownerReceiveBatch?.close();
|
|
290
306
|
}
|
|
307
|
+
const yieldTurn = this.yieldIfNeeded();
|
|
308
|
+
if (yieldTurn !== undefined)
|
|
309
|
+
await yieldTurn;
|
|
291
310
|
};
|
|
292
311
|
// An application worker drains the one owner it claimed. Infrastructure owners
|
|
293
312
|
// drain independently, so a suspended owner does not hold the other claims.
|
|
@@ -310,10 +329,8 @@ class ZLinkMeshDispatchPump {
|
|
|
310
329
|
const yieldTurn = this.yieldIfNeeded();
|
|
311
330
|
if (yieldTurn !== undefined)
|
|
312
331
|
await yieldTurn;
|
|
313
|
-
if (!drained.hasResidue) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
332
|
}
|
|
333
|
+
return false;
|
|
317
334
|
}
|
|
318
335
|
finally {
|
|
319
336
|
readyBatch.reset();
|
|
@@ -334,7 +351,7 @@ class ZLinkMeshDispatchPump {
|
|
|
334
351
|
}
|
|
335
352
|
async acquirePermit() {
|
|
336
353
|
try {
|
|
337
|
-
return await this.options.applicationJobQueue.acquire(this.capacityStop.signal);
|
|
354
|
+
return await this.options.applicationJobQueue.acquire(this.capacityStop.signal, 'remote');
|
|
338
355
|
}
|
|
339
356
|
catch (error) {
|
|
340
357
|
if (this.disposed || this.capacityStop.signal.aborted)
|
|
@@ -34,7 +34,12 @@ class ZLinkNodeChannelBackendAdapter {
|
|
|
34
34
|
return (0, node_socket_backend_adapter_1.wrapSocket)(node_backend_adapter_support_1.zlink.createDealerSocket(asNodeContext(context)), true);
|
|
35
35
|
}
|
|
36
36
|
createRouterSocket(context) {
|
|
37
|
-
|
|
37
|
+
const socket = node_backend_adapter_support_1.zlink.createRouterSocket(asNodeContext(context));
|
|
38
|
+
const adapter = (0, node_socket_backend_adapter_1.wrapSocket)(socket, true);
|
|
39
|
+
adapter.setReceiveFlowState = (state) => {
|
|
40
|
+
socket.setReceiveFlowState(state);
|
|
41
|
+
};
|
|
42
|
+
return adapter;
|
|
38
43
|
}
|
|
39
44
|
createPublisherSocket(context) {
|
|
40
45
|
return (0, node_socket_backend_adapter_1.wrapSocket)(node_backend_adapter_support_1.zlink.createPubSocket(asNodeContext(context)));
|
|
@@ -38,9 +38,10 @@ export declare function isRouteRecvRetryable(error: unknown): boolean;
|
|
|
38
38
|
export declare function submitBindingPublish(operation: ZLinkBindingPublishOperation, payload: unknown): void;
|
|
39
39
|
export declare function submitBindingReply(operation: ZLinkBindingReplyOperation, payload: unknown): void;
|
|
40
40
|
export declare function submitBindingAsyncSend(operation: ZLinkBindingAsyncSendOperation, payload: unknown): Promise<void>;
|
|
41
|
+
export declare function submitBindingSend(operation: ZLinkBindingAsyncSendOperation, payload: unknown): import('../raw-binding-port').ZLinkRawSendSubmission;
|
|
41
42
|
export declare function submitBindingSyncSend(operation: ZLinkBindingAsyncSendOperation, payload: unknown): void;
|
|
42
|
-
export declare function submitBindingRequest(operation: ZLinkBindingRequestOperation, payload: unknown, timeoutMs: number | undefined): Promise<readonly unknown[]>;
|
|
43
|
-
export declare function bindingRequestReply(submission: import('@zlink-systems/zlink').RequestSubmission, deadlineMs: number | undefined): Promise<import('@zlink-systems/zlink').Message[]>;
|
|
43
|
+
export declare function submitBindingRequest(operation: ZLinkBindingRequestOperation, payload: unknown, timeoutMs: number | undefined, recordReceived?: () => void, onAdmitted?: () => void): Promise<readonly unknown[]>;
|
|
44
|
+
export declare function bindingRequestReply(submission: import('@zlink-systems/zlink').RequestSubmission, deadlineMs: number | undefined, recordReceived?: () => void, onAdmitted?: () => void): Promise<import('@zlink-systems/zlink').Message[]>;
|
|
44
45
|
export declare function closeBindingReply(replies: readonly import('@zlink-systems/zlink').Message[]): void;
|
|
45
46
|
/**
|
|
46
47
|
* Closes a binding handle once. An already closed or terminated handle counts as
|
|
@@ -50,7 +51,6 @@ export declare function closeBindingHandle(target: {
|
|
|
50
51
|
close(): void;
|
|
51
52
|
}): void;
|
|
52
53
|
export declare function isContextTerminatedError(error: unknown): boolean;
|
|
53
|
-
export declare function disableSocketLinger(target: unknown): void;
|
|
54
54
|
export declare function toNativeRoutingId(routingId: unknown): unknown;
|
|
55
55
|
export declare function translateBindingResultError(error: unknown, phase?: 'submit' | 'completion'): unknown;
|
|
56
56
|
export declare function toNativeActorRef(actor: unknown): unknown;
|
|
@@ -6,13 +6,13 @@ exports.isRouteRecvRetryable = isRouteRecvRetryable;
|
|
|
6
6
|
exports.submitBindingPublish = submitBindingPublish;
|
|
7
7
|
exports.submitBindingReply = submitBindingReply;
|
|
8
8
|
exports.submitBindingAsyncSend = submitBindingAsyncSend;
|
|
9
|
+
exports.submitBindingSend = submitBindingSend;
|
|
9
10
|
exports.submitBindingSyncSend = submitBindingSyncSend;
|
|
10
11
|
exports.submitBindingRequest = submitBindingRequest;
|
|
11
12
|
exports.bindingRequestReply = bindingRequestReply;
|
|
12
13
|
exports.closeBindingReply = closeBindingReply;
|
|
13
14
|
exports.closeBindingHandle = closeBindingHandle;
|
|
14
15
|
exports.isContextTerminatedError = isContextTerminatedError;
|
|
15
|
-
exports.disableSocketLinger = disableSocketLinger;
|
|
16
16
|
exports.toNativeRoutingId = toNativeRoutingId;
|
|
17
17
|
exports.translateBindingResultError = translateBindingResultError;
|
|
18
18
|
exports.toNativeActorRef = toNativeActorRef;
|
|
@@ -22,6 +22,7 @@ const submission_result_1 = require("../../messaging/submission-result");
|
|
|
22
22
|
const node_backend_adapter_1 = require("../node-backend-adapter");
|
|
23
23
|
const runtime_values_1 = require("../runtime-values");
|
|
24
24
|
const nativeErrnoValues = node_os_1.constants.errno;
|
|
25
|
+
const completedSend = Promise.resolve();
|
|
25
26
|
exports.zlink = (0, node_backend_adapter_1.loadBinding)();
|
|
26
27
|
function isBindingNotFound(error) {
|
|
27
28
|
return error instanceof exports.zlink.ConnectError && error.result === exports.zlink.ConnectResult.NotFound;
|
|
@@ -75,7 +76,16 @@ function submitBindingReply(operation, payload) {
|
|
|
75
76
|
throw translateBindingResultError(error);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
function submitBindingAsyncSend(operation, payload) {
|
|
80
|
+
try {
|
|
81
|
+
const submission = submitBindingSend(operation, payload);
|
|
82
|
+
return submission.result === runtime_values_1.SubmitResult.Backpressured ? submission.admitted : completedSend;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return Promise.reject(error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function submitBindingSend(operation, payload) {
|
|
79
89
|
let submission;
|
|
80
90
|
try {
|
|
81
91
|
let current;
|
|
@@ -91,13 +101,15 @@ async function submitBindingAsyncSend(operation, payload) {
|
|
|
91
101
|
throw translateBindingResultError(error, 'submit');
|
|
92
102
|
}
|
|
93
103
|
if (submission.result === runtime_values_1.SubmitResult.Backpressured) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
104
|
+
return {
|
|
105
|
+
result: submission.result,
|
|
106
|
+
admitted: submission.admitted.catch((error) => {
|
|
107
|
+
throw translateBindingResultError(error, 'completion');
|
|
108
|
+
})
|
|
109
|
+
};
|
|
100
110
|
}
|
|
111
|
+
// Binding SendSubmission is the closed OK | BACKPRESSURED snapshot.
|
|
112
|
+
return submission;
|
|
101
113
|
}
|
|
102
114
|
function submitBindingSyncSend(operation, payload) {
|
|
103
115
|
try {
|
|
@@ -114,7 +126,7 @@ function submitBindingSyncSend(operation, payload) {
|
|
|
114
126
|
throw translateBindingResultError(error);
|
|
115
127
|
}
|
|
116
128
|
}
|
|
117
|
-
async function submitBindingRequest(operation, payload, timeoutMs) {
|
|
129
|
+
async function submitBindingRequest(operation, payload, timeoutMs, recordReceived, onAdmitted) {
|
|
118
130
|
const deadlineMs = timeoutMs === undefined ? undefined : performance.now() + timeoutMs;
|
|
119
131
|
try {
|
|
120
132
|
let current;
|
|
@@ -132,25 +144,32 @@ async function submitBindingRequest(operation, payload, timeoutMs) {
|
|
|
132
144
|
if (timeoutMs !== undefined) {
|
|
133
145
|
current = current.timeout(timeoutMs);
|
|
134
146
|
}
|
|
135
|
-
return await bindingRequestReply(current.submit(), deadlineMs);
|
|
147
|
+
return await bindingRequestReply(current.submit(), deadlineMs, recordReceived, onAdmitted);
|
|
136
148
|
}
|
|
137
149
|
catch (error) {
|
|
138
150
|
throw translateBindingResultError(error);
|
|
139
151
|
}
|
|
140
152
|
}
|
|
141
|
-
async function bindingRequestReply(submission, deadlineMs) {
|
|
153
|
+
async function bindingRequestReply(submission, deadlineMs, recordReceived, onAdmitted) {
|
|
142
154
|
const reply = submission.reply;
|
|
143
155
|
if (submission.result === runtime_values_1.SubmitResult.Backpressured) {
|
|
144
156
|
try {
|
|
145
|
-
const [, replies] = await (0, request_deadline_1.waitRequestReply)(Promise.all([submission.admitted, reply]), 'Request', deadlineMs);
|
|
157
|
+
const [, replies] = await (0, request_deadline_1.waitRequestReply)(Promise.all([submission.admitted.then(() => onAdmitted?.()), reply]), 'Request', deadlineMs);
|
|
158
|
+
recordReceived?.();
|
|
146
159
|
return replies;
|
|
147
160
|
}
|
|
148
161
|
catch (error) {
|
|
149
|
-
void reply.then(
|
|
162
|
+
void reply.then((parts) => {
|
|
163
|
+
recordReceived?.();
|
|
164
|
+
closeBindingReply(parts);
|
|
165
|
+
}, () => undefined);
|
|
150
166
|
throw error;
|
|
151
167
|
}
|
|
152
168
|
}
|
|
153
|
-
|
|
169
|
+
onAdmitted?.();
|
|
170
|
+
const replies = await reply;
|
|
171
|
+
recordReceived?.();
|
|
172
|
+
return replies;
|
|
154
173
|
}
|
|
155
174
|
function closeBindingReply(replies) {
|
|
156
175
|
for (const reply of replies)
|
|
@@ -182,23 +201,6 @@ function isSuccessfulOrAlreadyShutdownCloseError(error) {
|
|
|
182
201
|
function isContextTerminatedError(error) {
|
|
183
202
|
return error instanceof Error && /context was terminated/i.test(error.message);
|
|
184
203
|
}
|
|
185
|
-
function disableSocketLinger(target) {
|
|
186
|
-
if (target !== null &&
|
|
187
|
-
typeof target === 'object' &&
|
|
188
|
-
'options' in target &&
|
|
189
|
-
typeof target.options === 'object' &&
|
|
190
|
-
target.options !== null &&
|
|
191
|
-
'linger' in target.options) {
|
|
192
|
-
try {
|
|
193
|
-
target.options.linger = 0;
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
if (!isContextTerminatedError(error)) {
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
204
|
function toNativeRoutingId(routingId) {
|
|
203
205
|
if (typeof routingId === 'string')
|
|
204
206
|
return exports.zlink.RoutingId.from(routingId);
|
|
@@ -7,7 +7,7 @@ export declare class ZLinkDealerChannelClientTransport implements ZLinkChannelCl
|
|
|
7
7
|
private readonly publisher?;
|
|
8
8
|
constructor(dealer: DealerSocket, publisher?: PubSocket | undefined);
|
|
9
9
|
send(channelName: string, packetName: string | undefined, message: Message, metadata?: ReadonlyMap<string, string>): Promise<ZLinkSubmitResult>;
|
|
10
|
-
request<TReply>(channelName: string, packetName: string | undefined, request: Message, timeoutMs: number | undefined, signal?: AbortSignal, metadata?: ReadonlyMap<string, string
|
|
10
|
+
request<TReply>(channelName: string, packetName: string | undefined, request: Message, timeoutMs: number | undefined, signal?: AbortSignal, metadata?: ReadonlyMap<string, string>, onAdmitted?: () => void): Promise<TReply>;
|
|
11
11
|
tryPublish(channelName: string, topic: string, packetName: string | undefined, event: Message, metadata?: ReadonlyMap<string, string>): ZLinkSubmitResult;
|
|
12
12
|
publish(channelName: string, topic: string, packetName: string | undefined, event: Message, signal?: AbortSignal, metadata?: ReadonlyMap<string, string>): Promise<ZLinkSubmitResult>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZLinkDealerChannelClientTransport = void 0;
|
|
4
|
+
const node_backend_adapter_support_1 = require("./node-backend-adapter-support");
|
|
4
5
|
const configuration_1 = require("../../configuration");
|
|
5
6
|
const submission_result_1 = require("../../messaging/submission-result");
|
|
6
7
|
const channel_envelope_1 = require("../../channels/channel-envelope");
|
|
@@ -22,12 +23,14 @@ class ZLinkDealerChannelClientTransport {
|
|
|
22
23
|
await (0, flow_context_1.runWithOutboundFlow)(true, () => (0, channel_multipart_1.appendParts)(this.dealer.send(), (0, channel_envelope_1.encodeChannelEnvelopeParts)(3 /* ZLinkChannelMessageKind.Command */, channelName, packetName, message, undefined, undefined, undefined, undefined, true, metadata)).submit().admitted);
|
|
23
24
|
return { status: submission_result_1.ZLinkSubmitStatus.Submitted };
|
|
24
25
|
}
|
|
25
|
-
async request(channelName, packetName, request, timeoutMs, signal, metadata = EMPTY_METADATA) {
|
|
26
|
+
async request(channelName, packetName, request, timeoutMs, signal, metadata = EMPTY_METADATA, onAdmitted) {
|
|
26
27
|
(0, abort_1.throwIfAborted)(signal);
|
|
27
28
|
const operation = (0, flow_context_1.runWithOutboundFlow)(true, () => (0, channel_multipart_1.appendParts)(this.dealer.request(), (0, channel_envelope_1.encodeChannelEnvelopeParts)(1 /* ZLinkChannelMessageKind.Request */, channelName, packetName, request, timeoutMs, undefined, undefined, undefined, true, metadata)));
|
|
28
29
|
if (timeoutMs !== undefined)
|
|
29
30
|
operation.timeout(timeoutMs);
|
|
30
|
-
const reply = await (0, channel_multipart_1.submitRequestOperation)({
|
|
31
|
+
const reply = await (0, channel_multipart_1.submitRequestOperation)({
|
|
32
|
+
submit: () => (0, node_backend_adapter_support_1.bindingRequestReply)(operation.submit(), timeoutMs === undefined ? undefined : performance.now() + timeoutMs, undefined, onAdmitted)
|
|
33
|
+
}, 'channel request');
|
|
31
34
|
try {
|
|
32
35
|
return (0, channel_envelope_1.decodeChannelReply)(reply);
|
|
33
36
|
}
|