@zlink-systems/framework 0.30.3 → 0.32.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Actors/ZLinkActor.d.ts +2 -0
- package/dist/contracts/Actors/ZLinkSessionBindingIdentity.d.ts +6 -0
- package/dist/contracts/Actors/ZLinkSessionBindingIdentity.js +2 -0
- package/dist/contracts/Actors/index.d.ts +1 -0
- package/dist/contracts/Actors/index.js +1 -0
- package/dist/contracts/Common/CoreTypes.d.ts +1 -0
- package/dist/contracts/Common/HandlerMessageType.d.ts +8 -0
- package/dist/contracts/Common/HandlerMessageType.js +41 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +1 -1
- package/dist/contracts/Common/ZLinkEncodedPayload.js +12 -20
- package/dist/contracts/Common/ZLinkMessage.js +11 -7
- package/dist/contracts/Common/encoded-payload-storage.d.ts +0 -2
- package/dist/contracts/Common/encoded-payload-storage.js +4 -16
- package/dist/contracts/Common/index.d.ts +1 -1
- package/dist/contracts/Common/payload-slab.d.ts +4 -0
- package/dist/contracts/Common/payload-slab.js +30 -0
- package/dist/contracts/Configuration/RegistrationBuilders.js +15 -9
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +19 -0
- package/dist/contracts/Handlers/Contexts.d.ts +1 -0
- package/dist/contracts/Locations/Authority.d.ts +2 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +23 -1
- package/dist/nest-integration.d.ts +1 -0
- package/dist/nest-integration.js +3 -1
- package/dist/runtime/actors/actor-client.d.ts +6 -2
- package/dist/runtime/actors/actor-client.js +120 -82
- package/dist/runtime/actors/actor-context.js +16 -5
- package/dist/runtime/actors/actor-execution-context.js +2 -2
- package/dist/runtime/actors/actor-handoff.d.ts +12 -1
- package/dist/runtime/actors/actor-handoff.js +79 -34
- package/dist/runtime/actors/actor-join-deferred-scope.js +6 -6
- package/dist/runtime/actors/actor-local-native-join.d.ts +2 -2
- package/dist/runtime/actors/actor-local-native-join.js +19 -17
- package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
- package/dist/runtime/actors/actor-remote-joiner.d.ts +2 -2
- package/dist/runtime/actors/actor-remote-joiner.js +4 -4
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +9 -3
- package/dist/runtime/actors/actor-routed-json-request.d.ts +3 -0
- package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -2
- package/dist/runtime/actors/actor-runtime-state.d.ts +1 -1
- package/dist/runtime/actors/spot-actor-dispatch.d.ts +9 -5
- package/dist/runtime/actors/spot-actor-dispatch.js +60 -38
- package/dist/runtime/admission.d.ts +6 -4
- package/dist/runtime/admission.js +21 -10
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
- package/dist/runtime/backend/contracts/index.d.ts +26 -10
- package/dist/runtime/backend/mesh-completion-table.d.ts +7 -1
- package/dist/runtime/backend/mesh-completion-table.js +84 -20
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +19 -6
- package/dist/runtime/backend/mesh-dispatch-pump.js +246 -147
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -2
- package/dist/runtime/backend/node/node-backend-adapter-support.js +27 -19
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +5 -2
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +70 -13
- package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
- package/dist/runtime/backend/node/node-event-loop-poller.js +4 -3
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
- package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
- package/dist/runtime/backend/node/node-raw-binding-port.js +99 -63
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +34 -16
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +210 -106
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +20 -6
- package/dist/runtime/backend/raw-binding-port.d.ts +6 -3
- package/dist/runtime/channels/channel-clients.js +3 -3
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +11 -7
- package/dist/runtime/channels/channel-dispatch-pipeline.js +40 -22
- package/dist/runtime/channels/channel-dispatch-services.d.ts +3 -1
- package/dist/runtime/channels/channel-dispatch-services.js +7 -6
- package/dist/runtime/channels/channel-dispatchers.d.ts +13 -6
- package/dist/runtime/channels/channel-dispatchers.js +57 -36
- package/dist/runtime/channels/channel-envelope.d.ts +2 -2
- package/dist/runtime/channels/channel-envelope.js +609 -83
- package/dist/runtime/channels/channel-multipart.d.ts +1 -0
- package/dist/runtime/channels/channel-multipart.js +10 -6
- package/dist/runtime/channels/channel-outbound-operations.d.ts +6 -9
- package/dist/runtime/channels/channel-outbound-operations.js +107 -105
- package/dist/runtime/channels/channel-receive-loops.d.ts +9 -7
- package/dist/runtime/channels/channel-receive-loops.js +126 -90
- package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +23 -6
- package/dist/runtime/channels/channel-runtime-lifecycle.js +47 -38
- package/dist/runtime/channels/channel-runtime-manager.d.ts +13 -6
- package/dist/runtime/channels/channel-runtime-manager.js +32 -14
- package/dist/runtime/channels/channel-socket-registry.d.ts +28 -4
- package/dist/runtime/channels/channel-socket-registry.js +9 -1
- package/dist/runtime/channels/channel-transports.d.ts +23 -16
- package/dist/runtime/channels/channel-transports.js +139 -119
- package/dist/runtime/channels/dispatch-error-reporter.d.ts +4 -4
- package/dist/runtime/channels/dispatch-error-reporter.js +5 -5
- package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
- package/dist/runtime/channels/local-spot-route-transport.d.ts +5 -2
- package/dist/runtime/channels/local-spot-route-transport.js +15 -18
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +6 -3
- package/dist/runtime/channels/router-socket-spot-route-transport.js +33 -19
- package/dist/runtime/channels/source-spot-router.d.ts +6 -3
- package/dist/runtime/channels/source-spot-router.js +34 -23
- package/dist/runtime/channels/spot-node-route-transport.d.ts +6 -3
- package/dist/runtime/channels/spot-node-route-transport.js +23 -17
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +6 -3
- package/dist/runtime/channels/spot-route-bridge-transport.js +38 -24
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +8 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +36 -23
- package/dist/runtime/diagnostics/dispatch-error-details.js +9 -3
- package/dist/runtime/diagnostics/message-flow-bootstrap.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow-bootstrap.js +8 -0
- package/dist/runtime/diagnostics/message-flow-delivery.d.ts +47 -0
- package/dist/runtime/diagnostics/message-flow-delivery.js +149 -0
- package/dist/runtime/diagnostics/message-flow-record.d.ts +50 -0
- package/dist/runtime/diagnostics/message-flow-record.js +228 -0
- package/dist/runtime/diagnostics/message-flow-worker.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow-worker.js +118 -0
- package/dist/runtime/diagnostics/message-flow.d.ts +7 -19
- package/dist/runtime/diagnostics/message-flow.js +42 -290
- package/dist/runtime/diagnostics/runtime-metrics.d.ts +4 -3
- package/dist/runtime/diagnostics/runtime-metrics.js +8 -4
- package/dist/runtime/execution/index.d.ts +1 -0
- package/dist/runtime/execution/index.js +6 -3
- package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
- package/dist/runtime/execution/serial-execution-queue.js +75 -71
- package/dist/runtime/foundation/durable-service-request.d.ts +12 -3
- package/dist/runtime/foundation/durable-service-request.js +158 -73
- package/dist/runtime/foundation/operation-registry.d.ts +33 -3
- package/dist/runtime/foundation/operation-registry.js +272 -33
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +62 -23
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +373 -194
- package/dist/runtime/foundation/request-runtime.d.ts +17 -0
- package/dist/runtime/foundation/request-runtime.js +163 -0
- package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
- package/dist/runtime/foundation/service-discovery-registry.js +6 -0
- package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
- package/dist/runtime/foundation/service-mailbox.d.ts +4 -2
- package/dist/runtime/foundation/service-mailbox.js +4 -1
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -2
- package/dist/runtime/foundation/service-relocation-object-owner.js +12 -5
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +7 -2
- package/dist/runtime/foundation/service-stateful-registry.d.ts +6 -2
- package/dist/runtime/foundation/service-stateful-registry.js +38 -17
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +91 -26
- package/dist/runtime/foundation/service-stateful-runtime.js +245 -120
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
- package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
- package/dist/runtime/foundation/service-topology-registry.d.ts +2 -0
- package/dist/runtime/foundation/service-topology-registry.js +13 -3
- package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
- package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +5 -1
- package/dist/runtime/foundation/service-wire-m6a-codec.js +50 -15
- package/dist/runtime/host/actor-packet-relay.d.ts +5 -6
- package/dist/runtime/host/actor-packet-relay.js +58 -57
- package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
- package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
- package/dist/runtime/host/actor-runtime-options-factory.js +3 -2
- package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
- package/dist/runtime/host/application-job-queue.d.ts +7 -5
- package/dist/runtime/host/application-job-queue.js +33 -21
- package/dist/runtime/host/bound-session-relay.js +0 -1
- package/dist/runtime/host/channel-runtime-options-factory.d.ts +2 -0
- package/dist/runtime/host/channel-runtime-options-factory.js +1 -0
- package/dist/runtime/host/entry-actor-runtime.d.ts +5 -2
- package/dist/runtime/host/entry-actor-runtime.js +2 -2
- package/dist/runtime/host/index.d.ts +106 -37
- package/dist/runtime/host/index.js +303 -151
- package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
- package/dist/runtime/host/location-runtime-owner.js +1 -1
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +195 -45
- package/dist/runtime/host/service-relocation-host-runtime.js +257 -144
- package/dist/runtime/host/spot-address-transport.d.ts +3 -0
- package/dist/runtime/host/spot-address-transport.js +73 -76
- package/dist/runtime/host/spot-runtime-options-factory.js +2 -0
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -1
- package/dist/runtime/host/user-spot-creation-coordinator.js +49 -21
- package/dist/runtime/internal-observation.d.ts +1 -0
- package/dist/runtime/internal-observation.js +5 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +1 -1
- package/dist/runtime/locations/actor-location-claims.js +15 -6
- package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
- package/dist/runtime/locations/auto-connect-loop.js +25 -19
- package/dist/runtime/locations/auto-connect-planner.js +2 -5
- package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
- package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
- package/dist/runtime/locations/in-memory-authority-store.d.ts +1 -0
- package/dist/runtime/locations/in-memory-authority-store.js +15 -5
- package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
- package/dist/runtime/locations/in-memory-location-store.js +1 -38
- package/dist/runtime/locations/lifecycle.d.ts +1 -1
- package/dist/runtime/locations/lifecycle.js +2 -2
- package/dist/runtime/locations/location-store-repository.d.ts +0 -1
- package/dist/runtime/locations/location-store-repository.js +163 -246
- package/dist/runtime/locations/resolvers.d.ts +8 -1
- package/dist/runtime/locations/resolvers.js +16 -2
- package/dist/runtime/locations/runtime.d.ts +3 -3
- package/dist/runtime/locations/runtime.js +12 -16
- package/dist/runtime/messaging/creation-payload-codec.js +8 -7
- package/dist/runtime/messaging/framework-json-v1.d.ts +1 -1
- package/dist/runtime/messaging/framework-json-v1.js +6 -2
- package/dist/runtime/messaging/payload-codec.js +21 -35
- package/dist/runtime/messaging/request-deadline.d.ts +4 -2
- package/dist/runtime/messaging/request-deadline.js +40 -25
- package/dist/runtime/messaging/request-result.d.ts +14 -1
- package/dist/runtime/messaging/request-result.js +74 -13
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
- package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
- package/dist/runtime/spots/index.d.ts +28 -7
- package/dist/runtime/spots/index.js +31 -6
- package/dist/runtime/spots/spot-activation-registry.d.ts +3 -2
- package/dist/runtime/spots/spot-activation-registry.js +13 -8
- package/dist/runtime/spots/spot-activation-state.d.ts +2 -0
- package/dist/runtime/spots/spot-activation-state.js +1 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +9 -4
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +33 -12
- package/dist/runtime/spots/spot-actor-ingress-admission.d.ts +40 -0
- package/dist/runtime/spots/spot-actor-ingress-admission.js +78 -0
- package/dist/runtime/spots/spot-actor-membership.js +3 -3
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +16 -43
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +56 -113
- package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
- package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
- package/dist/runtime/spots/spot-entry-activation.d.ts +4 -3
- package/dist/runtime/spots/spot-entry-activation.js +7 -12
- package/dist/runtime/spots/spot-handler-registry.d.ts +5 -1
- package/dist/runtime/spots/spot-handler-registry.js +31 -15
- package/dist/runtime/spots/spot-manager-public.js +3 -2
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +11 -6
- package/dist/runtime/spots/spot-node-runtime-manager.js +6 -1
- package/dist/runtime/spots/spot-outbound.d.ts +8 -2
- package/dist/runtime/spots/spot-outbound.js +5 -5
- package/dist/runtime/spots/spot-route-packet-dispatch.js +13 -8
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +3 -3
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +9 -5
- package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -2
- package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
- package/dist/runtime/spots/spot-serial-turn-executor.js +20 -26
- package/dist/runtime/spots/spot-subscription-dispatch.js +5 -2
- package/dist/runtime/spots/spot-timer.d.ts +1 -1
- package/dist/runtime/streams/actor-session-binding-registry.d.ts +11 -3
- package/dist/runtime/streams/actor-session-binding-registry.js +28 -0
- package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
- package/dist/runtime/streams/bound-actor-relay-sender.js +3 -4
- package/dist/runtime/streams/bound-session-service.js +6 -7
- package/dist/runtime/streams/index.d.ts +3 -3
- package/dist/runtime/streams/index.js +22 -2
- package/dist/runtime/streams/managed-stream.js +2 -1
- package/dist/runtime/streams/session-calls.d.ts +1 -1
- package/dist/runtime/streams/session-calls.js +3 -9
- package/dist/runtime/streams/session-context.d.ts +2 -2
- package/dist/runtime/streams/session-context.js +2 -2
- package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
- package/dist/runtime/streams/stream-session-runtime.js +64 -33
- package/package.json +3 -3
- package/src/contracts/Actors/ZLinkActor.ts +6 -0
- package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
- package/src/contracts/Actors/index.ts +1 -0
- package/src/contracts/Common/CoreTypes.ts +1 -0
- package/src/contracts/Common/HandlerMessageType.ts +50 -0
- package/src/contracts/Common/ZLinkEncodedPayload.ts +13 -25
- package/src/contracts/Common/ZLinkMessage.ts +11 -7
- package/src/contracts/Common/encoded-payload-storage.ts +4 -16
- package/src/contracts/Common/index.ts +1 -1
- package/src/contracts/Common/payload-slab.ts +29 -0
- package/src/contracts/Configuration/RegistrationBuilders.ts +29 -15
- package/src/contracts/Configuration/RegistrationTypes.ts +19 -0
- package/src/contracts/Handlers/Contexts.ts +1 -0
- package/src/contracts/Locations/Authority.ts +7 -1
- package/src/internal.ts +17 -0
- package/src/nest-integration.ts +1 -0
- package/src/runtime/actors/actor-client.ts +257 -163
- package/src/runtime/actors/actor-context.ts +26 -14
- package/src/runtime/actors/actor-execution-context.ts +2 -2
- package/src/runtime/actors/actor-handoff.ts +86 -51
- package/src/runtime/actors/actor-join-deferred-scope.ts +6 -6
- package/src/runtime/actors/actor-local-native-join.ts +38 -17
- package/src/runtime/actors/actor-mailbox.ts +1 -1
- package/src/runtime/actors/actor-remote-joiner.ts +8 -4
- package/src/runtime/actors/actor-routed-join-transport.ts +13 -5
- package/src/runtime/actors/actor-routed-json-request.ts +3 -0
- package/src/runtime/actors/actor-runtime-contracts.ts +4 -2
- package/src/runtime/actors/actor-runtime-state.ts +1 -1
- package/src/runtime/actors/spot-actor-dispatch.ts +70 -68
- package/src/runtime/admission.ts +42 -15
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
- package/src/runtime/backend/contracts/index.ts +77 -10
- package/src/runtime/backend/mesh-completion-table.ts +106 -15
- package/src/runtime/backend/mesh-dispatch-pump.ts +294 -146
- package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -32
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +91 -34
- package/src/runtime/backend/node/node-event-loop-poller.ts +14 -5
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
- package/src/runtime/backend/node/node-raw-binding-port.ts +180 -69
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +386 -157
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +56 -11
- package/src/runtime/backend/raw-binding-port.ts +13 -5
- package/src/runtime/channels/channel-clients.ts +26 -11
- package/src/runtime/channels/channel-dispatch-pipeline.ts +77 -65
- package/src/runtime/channels/channel-dispatch-services.ts +7 -12
- package/src/runtime/channels/channel-dispatchers.ts +93 -39
- package/src/runtime/channels/channel-envelope.ts +680 -144
- package/src/runtime/channels/channel-multipart.ts +17 -13
- package/src/runtime/channels/channel-outbound-operations.ts +204 -178
- package/src/runtime/channels/channel-receive-loops.ts +160 -107
- package/src/runtime/channels/channel-runtime-lifecycle.ts +64 -59
- package/src/runtime/channels/channel-runtime-manager.ts +74 -27
- package/src/runtime/channels/channel-socket-registry.ts +20 -5
- package/src/runtime/channels/channel-transports.ts +414 -287
- package/src/runtime/channels/dispatch-error-reporter.ts +4 -9
- package/src/runtime/channels/local-spot-route-transport.ts +27 -29
- package/src/runtime/channels/router-socket-spot-route-transport.ts +63 -32
- package/src/runtime/channels/source-spot-router.ts +75 -38
- package/src/runtime/channels/spot-node-route-transport.ts +67 -37
- package/src/runtime/channels/spot-route-bridge-transport.ts +62 -30
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +105 -34
- package/src/runtime/diagnostics/dispatch-error-details.ts +10 -2
- package/src/runtime/diagnostics/message-flow-bootstrap.ts +6 -0
- package/src/runtime/diagnostics/message-flow-delivery.ts +171 -0
- package/src/runtime/diagnostics/message-flow-record.ts +295 -0
- package/src/runtime/diagnostics/message-flow-worker.ts +146 -0
- package/src/runtime/diagnostics/message-flow.ts +49 -362
- package/src/runtime/diagnostics/runtime-metrics.ts +10 -4
- package/src/runtime/execution/index.ts +6 -0
- package/src/runtime/execution/serial-execution-queue.ts +94 -96
- package/src/runtime/foundation/durable-service-request.ts +212 -89
- package/src/runtime/foundation/operation-registry.ts +287 -38
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +617 -292
- package/src/runtime/foundation/request-runtime.ts +227 -0
- package/src/runtime/foundation/service-discovery-registry.ts +7 -0
- package/src/runtime/foundation/service-liveness-registry.ts +1 -1
- package/src/runtime/foundation/service-mailbox.ts +7 -2
- package/src/runtime/foundation/service-relocation-object-owner.ts +21 -6
- package/src/runtime/foundation/service-runtime-contracts.ts +12 -2
- package/src/runtime/foundation/service-stateful-registry.ts +52 -19
- package/src/runtime/foundation/service-stateful-runtime.ts +365 -198
- package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
- package/src/runtime/foundation/service-topology-registry.ts +21 -3
- package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
- package/src/runtime/foundation/service-wire-m6a-codec.ts +69 -17
- package/src/runtime/host/actor-packet-relay.ts +160 -156
- package/src/runtime/host/actor-placement-coordinator.ts +1 -1
- package/src/runtime/host/actor-runtime-options-factory.ts +7 -2
- package/src/runtime/host/actor-transfer-runtime.ts +3 -3
- package/src/runtime/host/application-job-queue.ts +56 -27
- package/src/runtime/host/bound-session-relay.ts +0 -1
- package/src/runtime/host/channel-runtime-options-factory.ts +3 -0
- package/src/runtime/host/entry-actor-runtime.ts +14 -6
- package/src/runtime/host/index.ts +388 -113
- package/src/runtime/host/location-runtime-owner.ts +3 -3
- package/src/runtime/host/service-relocation-host-runtime.ts +380 -252
- package/src/runtime/host/spot-address-transport.ts +110 -95
- package/src/runtime/host/spot-runtime-options-factory.ts +3 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +69 -22
- package/src/runtime/internal-observation.ts +2 -0
- package/src/runtime/locations/actor-location-claims.ts +42 -16
- package/src/runtime/locations/auto-connect-loop.ts +24 -16
- package/src/runtime/locations/auto-connect-planner.ts +2 -5
- package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
- package/src/runtime/locations/in-memory-authority-store.ts +27 -7
- package/src/runtime/locations/in-memory-location-store.ts +1 -74
- package/src/runtime/locations/lifecycle.ts +4 -2
- package/src/runtime/locations/location-store-repository.ts +228 -308
- package/src/runtime/locations/resolvers.ts +20 -8
- package/src/runtime/locations/runtime.ts +16 -28
- package/src/runtime/messaging/creation-payload-codec.ts +12 -10
- package/src/runtime/messaging/framework-json-v1.ts +10 -1
- package/src/runtime/messaging/payload-codec.ts +50 -75
- package/src/runtime/messaging/request-deadline.ts +47 -39
- package/src/runtime/messaging/request-result.ts +88 -17
- package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
- package/src/runtime/spots/index.ts +57 -10
- package/src/runtime/spots/spot-activation-registry.ts +12 -8
- package/src/runtime/spots/spot-activation-state.ts +2 -0
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +62 -37
- package/src/runtime/spots/spot-actor-ingress-admission.ts +157 -0
- package/src/runtime/spots/spot-actor-membership.ts +8 -5
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +122 -206
- package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
- package/src/runtime/spots/spot-entry-activation.ts +25 -35
- package/src/runtime/spots/spot-handler-registry.ts +72 -15
- package/src/runtime/spots/spot-manager-public.ts +4 -2
- package/src/runtime/spots/spot-node-runtime-manager.ts +16 -7
- package/src/runtime/spots/spot-outbound.ts +26 -10
- package/src/runtime/spots/spot-route-packet-dispatch.ts +18 -8
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +14 -8
- package/src/runtime/spots/spot-runtime-ports.ts +5 -2
- package/src/runtime/spots/spot-serial-executor.ts +1 -1
- package/src/runtime/spots/spot-serial-turn-executor.ts +25 -40
- package/src/runtime/spots/spot-subscription-dispatch.ts +9 -2
- package/src/runtime/spots/spot-timer.ts +1 -1
- package/src/runtime/streams/actor-session-binding-registry.ts +46 -3
- package/src/runtime/streams/bound-actor-relay-sender.ts +16 -5
- package/src/runtime/streams/bound-session-service.ts +10 -7
- package/src/runtime/streams/index.ts +30 -4
- package/src/runtime/streams/managed-stream.ts +2 -1
- package/src/runtime/streams/session-calls.ts +9 -14
- package/src/runtime/streams/session-context.ts +6 -11
- package/src/runtime/streams/stream-session-runtime.ts +79 -40
- package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +0 -8
- package/dist/runtime/spots/spot-lifecycle-metrics.js +0 -17
- package/src/runtime/spots/spot-lifecycle-metrics.ts +0 -16
|
@@ -9,8 +9,27 @@ export declare class OperationCancelledError extends Error {
|
|
|
9
9
|
readonly operationId: bigint;
|
|
10
10
|
constructor(operationId: bigint, message?: string);
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface OperationHandle<T> {
|
|
13
13
|
readonly id: bigint;
|
|
14
|
+
readonly deadlineMs: number | undefined;
|
|
15
|
+
readonly promise?: Promise<T>;
|
|
16
|
+
complete(value: T, retentionMs?: number): boolean;
|
|
17
|
+
fail(reason: unknown): boolean;
|
|
18
|
+
takeFailure(reason: unknown): boolean;
|
|
19
|
+
resolveCaller(value: T): boolean;
|
|
20
|
+
rejectCaller(reason: unknown): boolean;
|
|
21
|
+
isPending(): boolean;
|
|
22
|
+
hasObserver(): boolean;
|
|
23
|
+
setFailureDispatcher(dispatcher: (reason: unknown) => void): void;
|
|
24
|
+
clearFailureDispatcher(dispatcher: (reason: unknown) => void): void;
|
|
25
|
+
setObserver(observer: OperationObserver<T, unknown>, context?: unknown): void;
|
|
26
|
+
deferCompletion(): void;
|
|
27
|
+
reply(value: T, retentionMs?: number): boolean;
|
|
28
|
+
replyFailure(reason: unknown): boolean;
|
|
29
|
+
setSignal(signal: AbortSignal | undefined): void;
|
|
30
|
+
mapCaller(onValue: (value: unknown) => unknown, onFailure: (error: unknown) => unknown): boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface PendingOperation<T> extends OperationHandle<T> {
|
|
14
33
|
readonly promise: Promise<T>;
|
|
15
34
|
}
|
|
16
35
|
/**
|
|
@@ -26,8 +45,10 @@ export interface OperationObserver<T, Context> {
|
|
|
26
45
|
export declare class OperationRegistry<T, Context = unknown> {
|
|
27
46
|
private readonly clock;
|
|
28
47
|
private readonly onPendingChanged?;
|
|
48
|
+
private readonly terminalError;
|
|
29
49
|
private readonly entries;
|
|
30
50
|
private nextId;
|
|
51
|
+
private lastVisitMs;
|
|
31
52
|
private deadlineCursor?;
|
|
32
53
|
/**
|
|
33
54
|
* A lower bound of the earliest pending deadline. Completed entries only
|
|
@@ -37,23 +58,32 @@ export declare class OperationRegistry<T, Context = unknown> {
|
|
|
37
58
|
private scanEarliestDeadlineMs;
|
|
38
59
|
private closed;
|
|
39
60
|
private pendingCount;
|
|
40
|
-
constructor(clock?: OperationClock, onPendingChanged?: (() => void) | undefined);
|
|
41
|
-
register(timeoutMs: number, timeoutOwner?: 'registry' | 'sender', context?: Context): PendingOperation<T>;
|
|
61
|
+
constructor(clock?: OperationClock, onPendingChanged?: (() => void) | undefined, terminalError?: (reason: unknown) => unknown);
|
|
62
|
+
register(timeoutMs: number, timeoutOwner?: 'registry' | 'sender', context?: Context, absoluteDeadlineMs?: number): PendingOperation<T>;
|
|
63
|
+
handle(id: bigint): OperationHandle<T>;
|
|
42
64
|
/** Registers an operation whose terminal goes to `observer` instead of a Promise. */
|
|
43
65
|
registerObserved(timeoutMs: number, observer: OperationObserver<T, Context>, context?: Context): bigint;
|
|
66
|
+
deadline(id: bigint): number | undefined;
|
|
67
|
+
setFailureDispatcher(id: bigint, dispatcher: (reason: unknown) => void): boolean;
|
|
68
|
+
clearFailureDispatcher(id: bigint, dispatcher: (reason: unknown) => void): void;
|
|
69
|
+
takeFailure(id: bigint, reason: unknown): boolean;
|
|
44
70
|
/** The time the next expiry pass has work, as a lower bound (spec 08 §4.2). */
|
|
45
71
|
nextDeadlineMs(): number;
|
|
46
72
|
private notePending;
|
|
47
73
|
complete(id: bigint, value: T, terminalContextRetentionMs?: number): boolean;
|
|
74
|
+
reply(id: bigint, value: T, terminalContextRetentionMs?: number): boolean;
|
|
48
75
|
fail(id: bigint, reason: unknown): boolean;
|
|
49
76
|
cancel(id: bigint, message?: string): boolean;
|
|
50
77
|
isPending(id: bigint): boolean;
|
|
78
|
+
setContext(id: bigint, context: Context): void;
|
|
51
79
|
context(id: bigint): Context | undefined;
|
|
80
|
+
clear(reason: unknown): void;
|
|
52
81
|
close(reason?: string): void;
|
|
53
82
|
failAll(reason: unknown): void;
|
|
54
83
|
get size(): number;
|
|
55
84
|
expire(nowMs: number, turnDeadlineMs: number): number;
|
|
56
85
|
private take;
|
|
86
|
+
private resetEmptyIndex;
|
|
57
87
|
private pendingEntry;
|
|
58
88
|
private retainTerminal;
|
|
59
89
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OperationRegistry = exports.OperationCancelledError = exports.OperationTimeoutError = void 0;
|
|
4
|
+
const abort_1 = require("../abort");
|
|
4
5
|
class OperationTimeoutError extends Error {
|
|
5
6
|
operationId;
|
|
6
7
|
constructor(operationId) {
|
|
@@ -19,6 +20,168 @@ class OperationCancelledError extends Error {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
exports.OperationCancelledError = OperationCancelledError;
|
|
23
|
+
class RegistryOperation {
|
|
24
|
+
registry;
|
|
25
|
+
id;
|
|
26
|
+
deadlineMs;
|
|
27
|
+
context;
|
|
28
|
+
promise;
|
|
29
|
+
resolve;
|
|
30
|
+
reject;
|
|
31
|
+
observer;
|
|
32
|
+
failureDispatcher;
|
|
33
|
+
terminalRetentionMs = 0;
|
|
34
|
+
signal;
|
|
35
|
+
callerValue;
|
|
36
|
+
callerFailure;
|
|
37
|
+
constructor(registry, id, deadlineMs, context) {
|
|
38
|
+
this.registry = registry;
|
|
39
|
+
this.id = id;
|
|
40
|
+
this.deadlineMs = deadlineMs;
|
|
41
|
+
this.context = context;
|
|
42
|
+
}
|
|
43
|
+
complete(value, retentionMs = this.terminalRetentionMs) {
|
|
44
|
+
if (this.promise !== undefined)
|
|
45
|
+
this.observer = undefined;
|
|
46
|
+
return this.registry.complete(this.id, value, retentionMs);
|
|
47
|
+
}
|
|
48
|
+
reply(value, retentionMs = 0) {
|
|
49
|
+
if (!this.isPending())
|
|
50
|
+
return false;
|
|
51
|
+
if (this.promise === undefined || this.observer === undefined)
|
|
52
|
+
return this.registry.complete(this.id, value, retentionMs);
|
|
53
|
+
const observer = this.observer;
|
|
54
|
+
this.observer = this;
|
|
55
|
+
if (observer !== this)
|
|
56
|
+
this.terminalRetentionMs = retentionMs;
|
|
57
|
+
observer.operationCompleted(this.id, value, this.context);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
replyFailure(reason) {
|
|
61
|
+
if (!this.isPending())
|
|
62
|
+
return false;
|
|
63
|
+
if (this.promise === undefined || this.observer === undefined)
|
|
64
|
+
return this.fail(reason);
|
|
65
|
+
const observer = this.observer;
|
|
66
|
+
this.observer = this;
|
|
67
|
+
observer.operationFailed(this.id, reason, this.context);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
setSignal(signal) {
|
|
71
|
+
this.signal = signal;
|
|
72
|
+
if (signal?.aborted === true)
|
|
73
|
+
this.handleEvent();
|
|
74
|
+
else
|
|
75
|
+
signal?.addEventListener('abort', this, { once: true });
|
|
76
|
+
}
|
|
77
|
+
handleEvent() {
|
|
78
|
+
this.fail(this.signal?.reason ?? (0, abort_1.createAbortError)());
|
|
79
|
+
}
|
|
80
|
+
detachSignal() {
|
|
81
|
+
this.signal?.removeEventListener('abort', this);
|
|
82
|
+
this.signal = undefined;
|
|
83
|
+
}
|
|
84
|
+
mapCaller(onValue, onFailure) {
|
|
85
|
+
if (this.resolve === undefined || this.reject === undefined)
|
|
86
|
+
return false;
|
|
87
|
+
const value = this.callerValue;
|
|
88
|
+
const failure = this.callerFailure;
|
|
89
|
+
this.callerValue =
|
|
90
|
+
value === undefined
|
|
91
|
+
? onValue
|
|
92
|
+
: (reply) => {
|
|
93
|
+
let mapped;
|
|
94
|
+
try {
|
|
95
|
+
mapped = value(reply);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw onFailure(error);
|
|
99
|
+
}
|
|
100
|
+
return onValue(mapped);
|
|
101
|
+
};
|
|
102
|
+
this.callerFailure =
|
|
103
|
+
failure === undefined
|
|
104
|
+
? onFailure
|
|
105
|
+
: (error) => {
|
|
106
|
+
let mapped = error;
|
|
107
|
+
try {
|
|
108
|
+
mapped = failure(error);
|
|
109
|
+
}
|
|
110
|
+
catch (reason) {
|
|
111
|
+
mapped = reason;
|
|
112
|
+
}
|
|
113
|
+
return onFailure(mapped);
|
|
114
|
+
};
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
fail(reason) {
|
|
118
|
+
return this.registry.fail(this.id, reason);
|
|
119
|
+
}
|
|
120
|
+
takeFailure(reason) {
|
|
121
|
+
return this.registry.takeFailure(this.id, reason);
|
|
122
|
+
}
|
|
123
|
+
isPending() {
|
|
124
|
+
return this.registry.isPending(this.id);
|
|
125
|
+
}
|
|
126
|
+
setFailureDispatcher(dispatcher) {
|
|
127
|
+
if (!this.registry.setFailureDispatcher(this.id, dispatcher) && this.promise !== undefined)
|
|
128
|
+
void this.promise.then(undefined, dispatcher);
|
|
129
|
+
}
|
|
130
|
+
clearFailureDispatcher(dispatcher) {
|
|
131
|
+
this.registry.clearFailureDispatcher(this.id, dispatcher);
|
|
132
|
+
}
|
|
133
|
+
hasObserver() {
|
|
134
|
+
return this.observer !== undefined;
|
|
135
|
+
}
|
|
136
|
+
setObserver(observer, context) {
|
|
137
|
+
if (context !== undefined)
|
|
138
|
+
this.context = context;
|
|
139
|
+
this.observer = observer;
|
|
140
|
+
}
|
|
141
|
+
deferCompletion() {
|
|
142
|
+
this.observer = this;
|
|
143
|
+
}
|
|
144
|
+
operationCompleted() { }
|
|
145
|
+
operationFailed() { }
|
|
146
|
+
resolveCaller(value) {
|
|
147
|
+
this.detachSignal();
|
|
148
|
+
const resolve = this.resolve, reject = this.reject, map = this.callerValue;
|
|
149
|
+
this.resolve = undefined;
|
|
150
|
+
this.reject = undefined;
|
|
151
|
+
this.callerValue = undefined;
|
|
152
|
+
this.callerFailure = undefined;
|
|
153
|
+
if (resolve === undefined)
|
|
154
|
+
return false;
|
|
155
|
+
try {
|
|
156
|
+
resolve(map === undefined ? value : map(value));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
reject?.(error);
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
rejectCaller(reason) {
|
|
164
|
+
this.detachSignal();
|
|
165
|
+
const reject = this.reject, map = this.callerFailure;
|
|
166
|
+
this.resolve = undefined;
|
|
167
|
+
this.reject = undefined;
|
|
168
|
+
this.callerValue = undefined;
|
|
169
|
+
this.callerFailure = undefined;
|
|
170
|
+
if (reject === undefined)
|
|
171
|
+
return false;
|
|
172
|
+
let failure = reason;
|
|
173
|
+
try {
|
|
174
|
+
if (map !== undefined)
|
|
175
|
+
failure = map(reason);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
failure = error;
|
|
179
|
+
}
|
|
180
|
+
reject(failure);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const DEADLINE_ROTATION_MS = 256;
|
|
22
185
|
const systemClock = {
|
|
23
186
|
now: () => performance.now()
|
|
24
187
|
};
|
|
@@ -26,8 +189,10 @@ const systemClock = {
|
|
|
26
189
|
class OperationRegistry {
|
|
27
190
|
clock;
|
|
28
191
|
onPendingChanged;
|
|
192
|
+
terminalError;
|
|
29
193
|
entries = new Map();
|
|
30
194
|
nextId = 1n;
|
|
195
|
+
lastVisitMs;
|
|
31
196
|
deadlineCursor;
|
|
32
197
|
/**
|
|
33
198
|
* A lower bound of the earliest pending deadline. Completed entries only
|
|
@@ -37,28 +202,36 @@ class OperationRegistry {
|
|
|
37
202
|
scanEarliestDeadlineMs = Number.POSITIVE_INFINITY;
|
|
38
203
|
closed = false;
|
|
39
204
|
pendingCount = 0;
|
|
40
|
-
constructor(clock = systemClock, onPendingChanged) {
|
|
205
|
+
constructor(clock = systemClock, onPendingChanged, terminalError = (reason) => reason) {
|
|
41
206
|
this.clock = clock;
|
|
42
207
|
this.onPendingChanged = onPendingChanged;
|
|
208
|
+
this.terminalError = terminalError;
|
|
209
|
+
this.lastVisitMs = this.clock.now();
|
|
43
210
|
}
|
|
44
|
-
register(timeoutMs, timeoutOwner = 'registry', context) {
|
|
211
|
+
register(timeoutMs, timeoutOwner = 'registry', context, absoluteDeadlineMs) {
|
|
45
212
|
if (this.closed)
|
|
46
213
|
throw new Error('Operation registry is closed.');
|
|
47
214
|
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
48
215
|
throw new RangeError('timeoutMs must be a non-negative finite number.');
|
|
49
216
|
}
|
|
50
217
|
const id = this.nextId++;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
218
|
+
const deadlineMs = timeoutOwner === 'registry'
|
|
219
|
+
? (absoluteDeadlineMs ?? this.clock.now() + timeoutMs)
|
|
220
|
+
: undefined;
|
|
221
|
+
const entry = new RegistryOperation(this, id, deadlineMs, context);
|
|
222
|
+
entry.promise = new Promise((resolve, reject) => {
|
|
223
|
+
entry.resolve = resolve;
|
|
224
|
+
entry.reject = reject;
|
|
56
225
|
});
|
|
57
|
-
const deadlineMs = timeoutOwner === 'registry' ? this.clock.now() + timeoutMs : undefined;
|
|
58
|
-
const entry = { context, deadlineMs, resolve, reject };
|
|
59
226
|
this.entries.set(id, entry);
|
|
60
227
|
this.notePending(deadlineMs);
|
|
61
|
-
return
|
|
228
|
+
return entry;
|
|
229
|
+
}
|
|
230
|
+
handle(id) {
|
|
231
|
+
const entry = this.entries.get(id);
|
|
232
|
+
if (!(entry instanceof RegistryOperation))
|
|
233
|
+
throw new Error(`Operation ${id} has no active registry entry.`);
|
|
234
|
+
return entry;
|
|
62
235
|
}
|
|
63
236
|
/** Registers an operation whose terminal goes to `observer` instead of a Promise. */
|
|
64
237
|
registerObserved(timeoutMs, observer, context) {
|
|
@@ -69,13 +242,44 @@ class OperationRegistry {
|
|
|
69
242
|
}
|
|
70
243
|
const id = this.nextId++;
|
|
71
244
|
const deadlineMs = this.clock.now() + timeoutMs;
|
|
72
|
-
this
|
|
245
|
+
const entry = new RegistryOperation(this, id, deadlineMs, context);
|
|
246
|
+
entry.observer = observer;
|
|
247
|
+
this.entries.set(id, entry);
|
|
73
248
|
this.notePending(deadlineMs);
|
|
74
249
|
return id;
|
|
75
250
|
}
|
|
251
|
+
deadline(id) {
|
|
252
|
+
return this.entries.get(id)?.deadlineMs;
|
|
253
|
+
}
|
|
254
|
+
setFailureDispatcher(id, dispatcher) {
|
|
255
|
+
const entry = this.pendingEntry(id);
|
|
256
|
+
if (entry === undefined)
|
|
257
|
+
return false;
|
|
258
|
+
entry.failureDispatcher = dispatcher;
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
clearFailureDispatcher(id, dispatcher) {
|
|
262
|
+
const entry = this.pendingEntry(id);
|
|
263
|
+
if (entry?.failureDispatcher === dispatcher)
|
|
264
|
+
entry.failureDispatcher = undefined;
|
|
265
|
+
}
|
|
266
|
+
takeFailure(id, reason) {
|
|
267
|
+
const entry = this.take(id);
|
|
268
|
+
if (entry === undefined)
|
|
269
|
+
return false;
|
|
270
|
+
entry.failureDispatcher = undefined;
|
|
271
|
+
entry.observer = undefined;
|
|
272
|
+
entry.context = undefined;
|
|
273
|
+
entry.rejectCaller(this.terminalError(reason));
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
76
276
|
/** The time the next expiry pass has work, as a lower bound (spec 08 §4.2). */
|
|
77
277
|
nextDeadlineMs() {
|
|
78
|
-
|
|
278
|
+
if (this.entries.size === 0)
|
|
279
|
+
return Number.POSITIVE_INFINITY;
|
|
280
|
+
if (this.deadlineCursor !== undefined)
|
|
281
|
+
return Math.min(this.lastVisitMs, this.earliestDeadlineMs);
|
|
282
|
+
return Math.min(this.earliestDeadlineMs, this.lastVisitMs + DEADLINE_ROTATION_MS);
|
|
79
283
|
}
|
|
80
284
|
notePending(deadlineMs) {
|
|
81
285
|
this.pendingCount++;
|
|
@@ -89,21 +293,33 @@ class OperationRegistry {
|
|
|
89
293
|
const entry = this.take(id);
|
|
90
294
|
if (entry === undefined)
|
|
91
295
|
return false;
|
|
92
|
-
|
|
93
|
-
|
|
296
|
+
entry.failureDispatcher = undefined;
|
|
297
|
+
const observer = entry.observer;
|
|
298
|
+
entry.observer = undefined;
|
|
299
|
+
if (observer !== undefined)
|
|
300
|
+
observer.operationCompleted(id, value, entry.context);
|
|
94
301
|
else
|
|
95
|
-
entry.
|
|
302
|
+
entry.resolveCaller(value);
|
|
96
303
|
this.retainTerminal(id, entry, terminalContextRetentionMs);
|
|
304
|
+
entry.context = undefined;
|
|
97
305
|
return true;
|
|
98
306
|
}
|
|
307
|
+
reply(id, value, terminalContextRetentionMs = 0) {
|
|
308
|
+
return this.pendingEntry(id)?.reply(value, terminalContextRetentionMs) ?? false;
|
|
309
|
+
}
|
|
99
310
|
fail(id, reason) {
|
|
100
311
|
const entry = this.take(id);
|
|
101
312
|
if (entry === undefined)
|
|
102
313
|
return false;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
314
|
+
reason = this.terminalError(reason);
|
|
315
|
+
const dispatch = entry.failureDispatcher;
|
|
316
|
+
entry.failureDispatcher = undefined;
|
|
317
|
+
dispatch?.(reason);
|
|
318
|
+
const observer = entry.observer;
|
|
319
|
+
entry.observer = undefined;
|
|
320
|
+
observer?.operationFailed(id, reason, entry.context);
|
|
321
|
+
entry.context = undefined;
|
|
322
|
+
entry.rejectCaller(reason);
|
|
107
323
|
return true;
|
|
108
324
|
}
|
|
109
325
|
cancel(id, message) {
|
|
@@ -112,9 +328,19 @@ class OperationRegistry {
|
|
|
112
328
|
isPending(id) {
|
|
113
329
|
return this.pendingEntry(id) !== undefined;
|
|
114
330
|
}
|
|
331
|
+
setContext(id, context) {
|
|
332
|
+
const entry = this.pendingEntry(id);
|
|
333
|
+
if (entry !== undefined)
|
|
334
|
+
entry.context = context;
|
|
335
|
+
}
|
|
115
336
|
context(id) {
|
|
116
337
|
return this.entries.get(id)?.context;
|
|
117
338
|
}
|
|
339
|
+
clear(reason) {
|
|
340
|
+
this.failAll(reason);
|
|
341
|
+
this.entries.clear();
|
|
342
|
+
this.resetEmptyIndex();
|
|
343
|
+
}
|
|
118
344
|
close(reason = 'Operation registry closed.') {
|
|
119
345
|
if (this.closed)
|
|
120
346
|
return;
|
|
@@ -122,7 +348,7 @@ class OperationRegistry {
|
|
|
122
348
|
for (const id of this.entries.keys())
|
|
123
349
|
this.cancel(id, reason);
|
|
124
350
|
this.entries.clear();
|
|
125
|
-
this.
|
|
351
|
+
this.resetEmptyIndex();
|
|
126
352
|
}
|
|
127
353
|
failAll(reason) {
|
|
128
354
|
for (const id of this.entries.keys())
|
|
@@ -132,13 +358,17 @@ class OperationRegistry {
|
|
|
132
358
|
return this.pendingCount;
|
|
133
359
|
}
|
|
134
360
|
expire(nowMs, turnDeadlineMs) {
|
|
361
|
+
if (this.entries.size === 0)
|
|
362
|
+
return 0;
|
|
135
363
|
let expired = 0;
|
|
364
|
+
if (this.deadlineCursor === undefined) {
|
|
365
|
+
this.lastVisitMs = nowMs;
|
|
366
|
+
this.deadlineCursor = this.entries.entries();
|
|
367
|
+
this.scanEarliestDeadlineMs = Number.POSITIVE_INFINITY;
|
|
368
|
+
}
|
|
369
|
+
const cursor = this.deadlineCursor;
|
|
136
370
|
while (this.clock.now() < turnDeadlineMs) {
|
|
137
|
-
|
|
138
|
-
this.deadlineCursor = this.entries.entries();
|
|
139
|
-
this.scanEarliestDeadlineMs = Number.POSITIVE_INFINITY;
|
|
140
|
-
}
|
|
141
|
-
const current = this.deadlineCursor.next();
|
|
371
|
+
const current = cursor.next();
|
|
142
372
|
if (current.done === true) {
|
|
143
373
|
this.deadlineCursor = undefined;
|
|
144
374
|
// Entries registered during the pass are appended and were scanned.
|
|
@@ -149,8 +379,11 @@ class OperationRegistry {
|
|
|
149
379
|
if (entry.deadlineMs === undefined)
|
|
150
380
|
continue;
|
|
151
381
|
if (entry.deadlineMs <= nowMs) {
|
|
152
|
-
if (!this.isPending(id))
|
|
382
|
+
if (!this.isPending(id)) {
|
|
153
383
|
this.entries.delete(id);
|
|
384
|
+
if (this.entries.size === 0)
|
|
385
|
+
this.resetEmptyIndex();
|
|
386
|
+
}
|
|
154
387
|
else if (this.fail(id, new OperationTimeoutError(id)))
|
|
155
388
|
expired++;
|
|
156
389
|
}
|
|
@@ -165,26 +398,32 @@ class OperationRegistry {
|
|
|
165
398
|
if (entry === undefined)
|
|
166
399
|
return undefined;
|
|
167
400
|
this.entries.delete(id);
|
|
401
|
+
if (this.entries.size === 0)
|
|
402
|
+
this.resetEmptyIndex();
|
|
168
403
|
this.pendingCount--;
|
|
169
404
|
if (this.pendingCount === 0)
|
|
170
405
|
this.onPendingChanged?.();
|
|
171
406
|
return entry;
|
|
172
407
|
}
|
|
408
|
+
resetEmptyIndex() {
|
|
409
|
+
this.deadlineCursor = undefined;
|
|
410
|
+
this.earliestDeadlineMs = Number.POSITIVE_INFINITY;
|
|
411
|
+
this.scanEarliestDeadlineMs = Number.POSITIVE_INFINITY;
|
|
412
|
+
}
|
|
173
413
|
pendingEntry(id) {
|
|
174
414
|
const entry = this.entries.get(id);
|
|
175
|
-
return entry
|
|
415
|
+
return entry instanceof RegistryOperation &&
|
|
416
|
+
(entry.resolve !== undefined || entry.observer !== undefined)
|
|
176
417
|
? entry
|
|
177
418
|
: undefined;
|
|
178
419
|
}
|
|
179
420
|
retainTerminal(id, entry, retentionMs) {
|
|
180
421
|
if (this.closed || entry.context === undefined || retentionMs === 0)
|
|
181
422
|
return;
|
|
182
|
-
entry.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.entries.set(id, entry);
|
|
187
|
-
this.earliestDeadlineMs = Math.min(this.earliestDeadlineMs, entry.deadlineMs);
|
|
423
|
+
const retained = { context: entry.context, deadlineMs: this.clock.now() + retentionMs };
|
|
424
|
+
this.entries.set(id, retained);
|
|
425
|
+
this.earliestDeadlineMs = Math.min(this.earliestDeadlineMs, retained.deadlineMs);
|
|
426
|
+
this.onPendingChanged?.();
|
|
188
427
|
}
|
|
189
428
|
}
|
|
190
429
|
exports.OperationRegistry = OperationRegistry;
|