Documentation

Hale.Base.Control.Concurrent.Green

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; bind uses BaseIO.bindTask to register the continuation without blocking.
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.

    Instances For
      @[inline]
      def Control.Concurrent.Green.GreenBase.bind {α β : Type} (x : GreenBase α) (f : αGreenBase β) :

      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
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[inline]

        Await a Task without blocking. The pool thread is freed.

        $$\text{await} : \text{Task}\ \alpha \to \text{GreenBase}\ \alpha$$

        Equations
        Instances For
          @[inline]

          Await a Concurrent α operation without blocking.

          $$\text{awaitConcurrent} : \text{Concurrent}\ \alpha \to \text{GreenBase}\ \alpha$$

          Equations
          Instances For
            @[inline]

            Convert to a Task for interop with IO.wait.

            Equations
            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 Task frees the pool thread (via GreenBase.bind).
              • Cancellable: takes a CancellationToken for cooperative cancellation.
              • Error-handling: exceptions propagate via Except.
              Equations
              Instances For
                @[inline]
                def Control.Concurrent.Green.Green.bind {α β : Type} (x : Green α) (f : αGreen β) :
                Equations
                Instances For
                  @[inline]
                  def Control.Concurrent.Green.Green.map {α β : Type} (f : αβ) (x : Green α) :
                  Equations
                  Instances For
                    @[inline]
                    Equations
                    Instances For
                      @[implicit_reducible]
                      Equations
                      • One or more equations did not get rendered due to their size.
                      @[implicit_reducible]
                      Equations
                      • One or more equations did not get rendered due to their size.
                      @[implicit_reducible]
                      Equations
                      • One or more equations did not get rendered due to their size.

                      Core operations #

                      @[inline]

                      Await a Concurrent α operation without blocking the pool thread.

                      Equations
                      Instances For
                        @[inline]

                        Check cancellation and throw if cancelled.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          MVar integration #

                          Chan integration #

                          QSem integration #

                          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.

                          Equations
                          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).

                              axiom Control.Concurrent.Green.GreenBase.await_resumes {α β : Type} (t : Task α) (f : αGreenBase β) :

                              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).