Greenlet — the result type #
A computation result that is either immediately available or pending.
.now a— value available, continuation runs synchronously..later t— value pending;bindusesBaseIO.bindTaskto register the continuation without blocking.
Instances For
Equations
- (Control.Concurrent.Green.Greenlet.now a).toTask = { get := a }
- (Control.Concurrent.Green.Greenlet.later t).toTask = t
Instances For
Equations
Instances For
GreenBase — the non-blocking IO monad #
The core green-thread monad (no error handling, no cancellation).
Wraps BaseIO (Greenlet α) with a custom bind that yields pool
threads on .later via BaseIO.bindTask.
Run the green computation, producing a
Greenlet.
Instances For
Equations
Instances For
Bind that yields the pool thread on .later.
Termination: O(1) beyond its arguments. bindTask registers a
callback and returns immediately.
Fairness: The .later branch calls BaseIO.bindTask, not IO.wait.
The pool thread is freed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Control.Concurrent.Green.GreenBase.map f x = { run := (fun (x : Control.Concurrent.Green.Greenlet α) => Control.Concurrent.Green.Greenlet.map f x) <$> x.run }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Control.Concurrent.Green.GreenBase.instFunctor = { map := fun {α β : Type} => Control.Concurrent.Green.GreenBase.map }
Equations
- Control.Concurrent.Green.GreenBase.instMonadLiftBaseIO = { monadLift := fun {α : Type} (x : BaseIO α) => { run := Control.Concurrent.Green.Greenlet.now <$> x } }
Await a Task without blocking. The pool thread is freed.
$$\text{await} : \text{Task}\ \alpha \to \text{GreenBase}\ \alpha$$
Equations
Instances For
Await a Concurrent α operation without blocking.
$$\text{awaitConcurrent} : \text{Concurrent}\ \alpha \to \text{GreenBase}\ \alpha$$
Equations
- Control.Concurrent.Green.GreenBase.awaitConcurrent op = { run := do let task ← op pure (Control.Concurrent.Green.Greenlet.later task) }
Instances For
Green — the full green-thread monad #
A fair green-thread computation with cancellation and error handling.
$$\text{Green}\ \alpha := \text{CancellationToken} \to \text{GreenBase}\ (\text{Except}\ \text{IO.Error}\ \alpha)$$
- Fair: awaiting a
Taskfrees the pool thread (viaGreenBase.bind). - Cancellable: takes a
CancellationTokenfor cooperative cancellation. - Error-handling: exceptions propagate via
Except.
Equations
Instances For
Equations
Instances For
Equations
- x.bind f token = (x token).bind fun (x : Except IO.Error α) => match x with | Except.ok a => f a token | Except.error e => Control.Concurrent.Green.GreenBase.pure (Except.error e)
Instances For
Equations
- Control.Concurrent.Green.Green.map f x token = Control.Concurrent.Green.GreenBase.map (fun (x : Except IO.Error α) => Except.map f x) (x token)
Instances For
Equations
Instances For
Equations
- x.tryCatch h token = (x token).bind fun (x : Except IO.Error α) => match x with | Except.ok a => Control.Concurrent.Green.GreenBase.pure (Except.ok a) | Except.error e => h e token
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Control.Concurrent.Green.Green.instFunctor = { map := fun {α β : Type} => Control.Concurrent.Green.Green.map }
Equations
- Control.Concurrent.Green.Green.instMonadExceptError = { throw := fun {α : Type} => Control.Concurrent.Green.Green.throw, tryCatch := fun {α : Type} => Control.Concurrent.Green.Green.tryCatch }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Core operations #
Await a Concurrent α operation without blocking the pool thread.
Equations
Instances For
Check cancellation and throw if cancelled.
Equations
- One or more equations did not get rendered due to their size.
Instances For
MVar integration #
Equations
Instances For
Equations
Instances For
Equations
Instances For
Chan integration #
Equations
Instances For
QSem integration #
Equations
Instances For
Equations
Instances For
Running Green computations #
Run a Green computation, returning a Task that resolves when the
entire continuation chain completes. No pool thread is blocked during
any await.
Instances For
Run a Green computation and block until it completes (top-level only).
Equations
Instances For
Axiom-dependent properties #
Termination: GreenBase.bind x f terminates if x terminates
and f a terminates for all a. Axiom-dependent on lean_io_bind_task
returning in O(1).
Liveness: GreenBase.await t >>= f calls f iff t resolves.
Axiom-dependent on lean_io_bind_task invoking the callback exactly
once on task completion.
Fairness: GreenBase.bind never blocks the pool thread.
Structural: uses BaseIO.bindTask (non-blocking), not IO.wait (blocking).