Chapter 8
Parallel and Watch
Bounded parallel work, cancellation, and filesystem event streams.
Bounded parallelism
let urls = [
"https://example.com",
"https://example.org"
]
urls
|> parallel(2) { url ->
http.get(url)
|> timeout(5s)
|> send
}
|> printparallel(n) runs at most n isolated workers and emits results in input order. One failure cancels the remaining tasks. Values crossing worker boundaries must pass Sendable validation.
Watch filesystem changes
watch(path("./src"))
|> where { event -> event.kind == "write" }
|> debounce(300ms)
|> for_each { event ->
print(event.path)
}watch returns an infinite FileEvent Stream. Compose automation with debounce, where, take, and other Flow operators; Ctrl+C uses the same cancellation path.
