From 35e2cba2e90f3ecbd9f79083d7369de716e2a281 Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Sun, 7 Jun 2026 22:05:39 +0200 Subject: [PATCH] fix: replace removed Thread.sleep in concurrency.md (#314) Thread.sleep, Time.Duration.fromSeconds, and the single-arg Channel.timeout no longer exist in the current Flix API. - Drop the slowPrint helper from the structured-concurrency example; it only existed to inject a Thread.sleep delay. - In the timeout example, reproduce the slow sender's delay with a Channel.timeout receiver (Chan + IO, both legal in spawn) since the new Sleep effect is not allowed inside spawn. Update Channel.timeout calls to the two-argument (Int32, Time.TimeUnit) form. Both examples verified with flix check (0.72.0). Closes #314 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/concurrency.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/concurrency.md b/src/concurrency.md index 243543d3..7e4c8759 100644 --- a/src/concurrency.md +++ b/src/concurrency.md @@ -18,15 +18,11 @@ Spawned processes are always associated with a region; the region will not exit until all the processes associated with it have completed: ```flix -def slowPrint(delay: Int32, message: String): Unit \ IO = - Thread.sleep(Time.Duration.fromSeconds(delay)); - println(message) - def main(): Unit \ IO = region r1 { region r2 { - spawn slowPrint(2, "Hello from r1") @ r1; - spawn slowPrint(1, "Hello from r2") @ r2 + spawn println("Hello from r1") @ r1; + spawn println("Hello from r2") @ r2 }; println("r2 is now complete") }; @@ -150,14 +146,15 @@ a channel, but the `select` expression relies on giving up: ```flix -def slow(tx: Sender[String]): Unit \ {Chan, IO} = - Thread.sleep(Time.Duration.fromSeconds(60)); +def slow(tx: Sender[String]): Unit \ {Chan, NonDet, IO} = + let delay = Channel.timeout(60, Time.TimeUnit.Seconds); + Channel.recv(delay); Channel.send("I am very slow", tx) def main(): Unit \ {Chan, NonDet, IO} = region rc { let (tx, rx) = Channel.buffered(1); spawn slow(tx) @ rc; - let timeout = Channel.timeout(Time.Duration.fromSeconds(5)); + let timeout = Channel.timeout(5, Time.TimeUnit.Seconds); select { case m <- recv(rx) => m case _ <- recv(timeout) => "timeout"