mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
Use Ref for request response stop state
This commit is contained in:
parent
e46fc64275
commit
48710a0518
3 changed files with 30 additions and 4 deletions
|
|
@ -472,6 +472,8 @@ describe("Effect-native messaging runtime", () => {
|
|||
operation: "stop",
|
||||
resource: "tg.test.request:tg.test.response",
|
||||
});
|
||||
expect(backend.producer.closeCount).toBe(1);
|
||||
expect(responseConsumer.closeCount).toBe(1);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -509,11 +509,12 @@ export const makeEffectRequestResponseFromPubSub = Effect.fn("makeEffectRequestR
|
|||
const responses = yield* EffectPubSub.unbounded<ResponseEnvelope<TRes>>();
|
||||
const stoppedSignal = yield* Deferred.make<never, MessagingLifecycleError>();
|
||||
const fiber = yield* dispatchResponseLoop(backend, options.responseTopic, responses, config).pipe(Effect.forkScoped);
|
||||
let stopped = false;
|
||||
const stopped = yield* Ref.make(false);
|
||||
|
||||
const stop = Effect.fn(`RequestResponse.stop:${options.requestTopic}`)(function* () {
|
||||
if (stopped) return;
|
||||
stopped = true;
|
||||
const alreadyStopped = yield* Ref.getAndSet(stopped, true);
|
||||
if (alreadyStopped) return;
|
||||
|
||||
yield* Deferred.fail(
|
||||
stoppedSignal,
|
||||
messagingLifecycleError(`${options.requestTopic}:${options.responseTopic}`, "stop", "RequestResponse stopped"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue