Created
July 25, 2025 09:17
-
-
Save thealmikey/2a725c60edbb316e3723387107dc6338 to your computer and use it in GitHub Desktop.
confessions
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
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