@@ -81,7 +81,7 @@ import fs2.internal.InterruptContext.InterruptionOutcome
81
81
private [fs2] final class Scope [F [_]] private (
82
82
val id : Unique .Token ,
83
83
private val parent : Option [Scope [F ]],
84
- interruptible : Option [InterruptContext [F ]],
84
+ private val interruptible : Option [InterruptContext [F ]],
85
85
private val state : Ref [F , Scope .State [F ]]
86
86
)(implicit val F : Compiler .Target [F ]) { self =>
87
87
@@ -276,6 +276,13 @@ private[fs2] final class Scope[F[_]] private (
276
276
case _ : Scope .State .Closed [F ] => F .pure(Right (()))
277
277
}
278
278
279
+ /** Like `openAncestor` but returns self if open. */
280
+ private def openScope : F [Scope [F ]] =
281
+ state.get.flatMap {
282
+ case _ : Scope .State .Open [F ] => F .pure(self)
283
+ case _ : Scope .State .Closed [F ] => openAncestor
284
+ }
285
+
279
286
/** Returns closest open parent scope or root. */
280
287
def openAncestor : F [Scope [F ]] =
281
288
self.parent.fold(F .pure(self)) { parent =>
@@ -412,13 +419,13 @@ private[fs2] final class Scope[F[_]] private (
412
419
iCtx.completeWhen(outcome)
413
420
}
414
421
415
- /** Checks if current scope is interrupted.
422
+ /** Checks if the nearest open scope is interrupted.
416
423
* If yields to None, scope is not interrupted and evaluation may normally proceed.
417
- * If yields to Some(Right(scope,next)) that yields to next `scope`, that has to be run and `next` stream
424
+ * If yields to Some(Right(scope,next)) that yields to next `scope`, that has to be run and `next` stream
418
425
* to evaluate
419
426
*/
420
427
def isInterrupted : F [Option [InterruptionOutcome ]] =
421
- interruptible match {
428
+ openScope.map(_. interruptible).flatMap {
422
429
case None => F .pure(None )
423
430
case Some (iCtx) => iCtx.ref.get
424
431
}
0 commit comments