Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions core/shared/src/main/scala/zio/ZScope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sealed trait ZScope[+A] { self =>
* is closed. The returned effect will succeed with `true` if the finalizer
* will not be run by this scope, and `false` otherwise.
*/
def deny(key: => ZScope.Key): UIO[Boolean]
def deny(key: => ZScope.Key): UIO[Boolean] = UIO(unsafeDeny(key))

/**
* Determines if the scope is empty (has no finalizers) at the instant the
Expand Down Expand Up @@ -88,6 +88,7 @@ sealed trait ZScope[+A] { self =>
*/
def released: UIO[Boolean]

private[zio] def unsafeDeny(key: ZScope.Key): Boolean
private[zio] def unsafeEnsure(finalizer: A => UIO[Any], mode: ZScope.Mode): Option[ZScope.Key]
private[zio] def unsafeExtend(that: ZScope[Any]): Boolean
}
Expand Down Expand Up @@ -128,14 +129,13 @@ object ZScope {

def closed: UIO[Boolean] = UIO(false)

def deny(key: => Key): UIO[Boolean] = UIO(true)

def empty: UIO[Boolean] = UIO(false)

def ensure(finalizer: Nothing => UIO[Any], mode: ZScope.Mode = ZScope.Mode.Strong): UIO[Option[Key]] = ensureResult

def released: UIO[Boolean] = UIO(false)

private[zio] def unsafeDeny(key: Key): Boolean = true
private[zio] def unsafeEnsure(finalizer: Nothing => UIO[Any], mode: ZScope.Mode): Option[Key] = unsafeEnsureResult
private[zio] def unsafeExtend(that: ZScope[Any]): Boolean = that match {
case local: Local[_] => local.unsafeAddRef()
Expand Down Expand Up @@ -194,8 +194,6 @@ object ZScope {

def closed: UIO[Boolean] = UIO(unsafeClosed())

def deny(key: => Key): UIO[Boolean] = UIO(unsafeDeny(key))

def empty: UIO[Boolean] = UIO(Sync(self)(weakFinalizers.size() == 0 && strongFinalizers.size() == 0))

def ensure(finalizer: A => UIO[Any], mode: ZScope.Mode = ZScope.Mode.Strong): UIO[Option[Key]] =
Expand Down
4 changes: 4 additions & 0 deletions core/shared/src/main/scala/zio/internal/FiberContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ private[zio] final class FiberContext[E, A](
childContext.scopeKey = key.getOrElse(
throw new IllegalStateException("Defect: The fiber's scope has ended before the fiber itself has ended")
)

// Remove the finalizer key from the parent scope when the child fiber
// terminates:
childContext.onDone(_ => key.foreach(parentScope.unsafeDeny))
}

executor.submitOrThrow(() => childContext.evaluateNow(zio))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import zio.duration._
import zio.stm.TQueue
import zio.stream.ZSink.Push
import zio.test.Assertion._
import zio.test.TestAspect.{ flaky, nonFlaky, timeout }
import zio.test.TestAspect.{ exceptJS, flaky, nonFlaky, timeout }
import zio.test._
import zio.test.environment.TestClock

Expand Down Expand Up @@ -2014,7 +2014,7 @@ object ZStreamSpec extends ZIOBaseSpec {
_ <- queue1.offer(1)
result <- fiber.join
} yield assert(result)(equalTo(Chunk(2, 3)))
}
} @@ exceptJS
),
suite("mergeTerminateEither")(
testM("terminates as soon as either stream terminates") {
Expand Down