Skip to content

Instantly share code, notes, and snippets.

@guersam
Created March 15, 2023 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guersam/7bbe41d17ab025d323bc4e64b20217b8 to your computer and use it in GitHub Desktop.
Save guersam/7bbe41d17ab025d323bc4e64b20217b8 to your computer and use it in GitHub Desktop.
`ZIO#interruptible` can override a fiber's interruptibility inherited from its parent
//> 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"))
}
@guersam
Copy link
Author

guersam commented Mar 15, 2023

Use Scala CLI to run

$ scala-cli https://gist.github.com/guersam/7bbe41d17ab025d323bc4e64b20217b8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment