EN
importPour l'utiliser : import Concur

Structured concurrency — the Concur effect

Synopsis
data Reply a = Go a | Stop

The scheduler's reply when it resumes a suspended fibre: Go v delivers the awaited value; Stop asks the fibre to CANCEL (it was cancelled by its scope).

await : Fiber a -> a with Concur

Suspend the current fibre until fib resolves, yielding its value. If the current fibre is itself cancelled while waiting, it unwinds here instead.

yield : () with Concur

Cooperative reschedule point — hand control to the scheduler (equity + a cancellation checkpoint).

scope : (Group e -> a with Concur, Throw e) -> a with Concur, Throw e

A NURSERY (structured scope). Runs body with a fresh Group; children spawned into the group via spawnIn are OWNED by the scope. scope returns only once EVERY child has settled (no leak). If a child FAILS, the siblings are CANCELLED — each unwinding its brackets — and the error is re-raised in the parent. The child error type e flows through Group e to the re-raised throw e.

concurrently : (() -> a with Concur, Throw e) -> (() -> b with Concur, Throw e) -> (a, b) with Concur, Throw e

Run two computations concurrently and return both results. If either fails, the other is cancelled and the error propagates.

parallel : List (() -> a with Concur, Throw e) -> List a with Concur, Throw e

Run a list of computations concurrently and collect their results IN ORDER. If any fails, the rest are cancelled and the error propagates.

race : (() -> a with Concur, Throw e) -> (() -> a with Concur, Throw e) -> a with Concur, Throw e

Race two computations: the FIRST to finish wins, the loser is CANCELLED. If the first to settle FAILS, the scope fails and its error propagates (the other is cancelled too).

bracket : (() -> r with e) -> (r -> b with e) -> (r -> a with e) -> a with e

bracket acquire release use: acquire a resource, run use with it, and run release EXACTLY ONCE on every exit — normal completion, a throw, or a structured CANCELLATION.

finally : (() -> a with e) -> (() -> b with e) -> a with e

finally action cleanup: run action, then run cleanup on every exit (normal, throw, or cancellation).