From d11a74b738aeccbbfdfb41c42071507d60be4e67 Mon Sep 17 00:00:00 2001 From: Dor Shtaif Date: Wed, 4 Oct 2023 17:09:04 +0300 Subject: [PATCH] refactor: internal logic fix in the multicast channel code (no public behavior impact) - ensure to mark a channel's iterator as closed for further pull attempts as soon as it realizes its parent channel itself had already ended/errored out (#47) --- src/utils/createMulticastChannel.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/createMulticastChannel.ts b/src/utils/createMulticastChannel.ts index d4fbe79..2d603f1 100644 --- a/src/utils/createMulticastChannel.ts +++ b/src/utils/createMulticastChannel.ts @@ -66,11 +66,11 @@ function createMulticastChannel(): MulticastChannel { return { done: false, value: listHead.item }; } - if (channelState === ChannelInternalState.CLOSED) { - return { done: true, value: undefined }; - } - - if (channelState === ChannelInternalState.ERROR) { + if (channelState !== ChannelInternalState.ACTIVE) { + isIteratorClosed = true; + if (channelState === ChannelInternalState.CLOSED) { + return { done: true, value: undefined }; + } throw channelErrorValue; }