Skip to content

Instantly share code, notes, and snippets.

@thealmikey
Created July 25, 2025 09:17
Show Gist options
  • Save thealmikey/2a725c60edbb316e3723387107dc6338 to your computer and use it in GitHub Desktop.
Save thealmikey/2a725c60edbb316e3723387107dc6338 to your computer and use it in GitHub Desktop.
confessions
package puppyz
import zio._
import zio.ZIO.log
import zio.Duration
object confessions extends ZIOAppDefault {
def confessLove: UIO[Unit] =
ZIO.uninterruptibleMask { restore =>
for {
_ <- log("πŸŽ™οΈ Recording: 'No one can stop our love...'")
_ <- restore(ZIO.sleep(7.seconds)) //we simulate delay here so we can interrupt - we're interruptable for 7s
.onInterrupt(log("πŸ’” Message deleted before sending."))
_ <- log("πŸ“€ Sent! The hearts have been delivered.")
} yield ()
}
override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] =
for {
fiber <- confessLove.fork
_ <- ZIO.sleep(2.seconds) // Wait a bit before interrupting(we interrupt before 7 seconds are up, play here)
_ <- log("πŸ›‘ Parent opened the door.")
_ <- fiber.interrupt
_ <- fiber.join // Observe what happened
} yield ()
// override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] =
// for {
// fiber <- confessLove.fork
// _ <- ZIO.sleep(10.seconds) // Wait a bit before interrupting(we interrupt before 7 seconds are up, play here)
// _ <- log("πŸ›‘ Parent opened the door but still sent.")
// _ <- fiber.interrupt
// _ <- fiber.join // Observe what happened
// } yield ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment