From e0e35e8f4a17834f003676a45047ea90d11a908c Mon Sep 17 00:00:00 2001 From: Ruslan Shevchenko Date: Mon, 20 May 2024 10:26:01 +0300 Subject: [PATCH] fixed potential bug in js stream, when we reading from finished stream --- .../scala/cps/stream/BaseUnfoldCpsAsyncEmitAbsorber.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/src/main/scala/cps/stream/BaseUnfoldCpsAsyncEmitAbsorber.scala b/js/src/main/scala/cps/stream/BaseUnfoldCpsAsyncEmitAbsorber.scala index dcfd09c89..d569a3a15 100644 --- a/js/src/main/scala/cps/stream/BaseUnfoldCpsAsyncEmitAbsorber.scala +++ b/js/src/main/scala/cps/stream/BaseUnfoldCpsAsyncEmitAbsorber.scala @@ -123,8 +123,12 @@ trait BaseUnfoldCpsAsyncEmitAbsorber[R,F[_],C<:CpsMonadContext[F], T](using ec: val e = state.supplyEvents.dequeue() asyncMonad.pure(e) else - state.queueConsumer() - + state.finishRef.get() match + case null => + state.queueConsumer() + case finished => + asyncMonad.pure(Finished(finished)) + val r = state.finishRef.get() if r eq null then asyncMonad.flatMap(nextEvent())(e => handleEvent(e))