Created
March 15, 2023 03:06
-
-
Save guersam/7bbe41d17ab025d323bc4e64b20217b8 to your computer and use it in GitHub Desktop.
`ZIO#interruptible` can override a fiber's interruptibility inherited from its parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "3.2.2" | |
//> using dep "dev.zio::zio:2.0.10" | |
import zio.* | |
object ResourceAcquisitionTimeoutExample extends ZIOAppDefault { | |
val run = | |
ZIO.debug("Running...") *> | |
ZIO.acquireRelease( | |
ZIO.debug("Acquired") | |
.delay(3.seconds) | |
.onInterrupt(ZIO.debug("Interrupt Detected")) | |
.timeoutFail("Interrupted")(1.second) | |
.interruptible // necessary for timeout | |
)(_ => ZIO.debug("Released")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Scala CLI to run