Documentation

Std.Internal.Async.ContextAsync

This module contains the implementation of ContextAsync, a monad for asynchronous computations with cooperative cancellation support that must be explicitly checked for and cancelled explicitly.

@[reducible, inline]

An asynchronous computation with cooperative cancellation support via a CancellationContext. ContextAsync α is equivalent to ReaderT CancellationContext Async α, providing a CancellationContext value to async computations.

Equations
Instances For
    @[inline]

    Runs a ContextAsync computation with a given context. See also ContextAsync.run for running with a new context that automatically cancels after execution.

    Equations
    Instances For
      @[inline]

      Runs a ContextAsync computation with a new context that cancels after the execution of the computation. See also ContextAsync.runIn for running with an existing context.

      Equations
      Instances For
        @[inline]

        Returns the current context for inspection or to pass to other functions.

        Equations
        Instances For
          @[inline]

          Checks if the current context is cancelled. Returns true if the context (or any ancestor) has been cancelled. Long-running operations should periodically check this and exit gracefully when cancelled.

          Equations
          Instances For
            @[inline]

            Gets the cancellation reason if the context is cancelled. Returns some reason if cancelled, none otherwise, allowing you to distinguish between different cancellation types.

            Equations
            Instances For
              @[inline]

              Cancels the current context with the given reason, cascading to all child contexts. Cancellation is cooperative, operations must explicitly check isCancelled or use awaitCancellation to respond.

              Equations
              Instances For
                @[inline]

                Returns a selector that completes when the current context is cancelled.

                Equations
                Instances For
                  @[inline, specialize #[]]

                  Runs two computations concurrently and returns both results. Each computation runs in its own child context; if either fails or is cancelled, both are cancelled immediately and the exception is propagated.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    @[inline, specialize #[]]

                    Runs two computations concurrently and returns the result of the first to complete. Each computation runs in its own child context; when either completes, the other is cancelled immediately.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      @[inline, specialize #[]]

                      Runs all computations concurrently and collects results in the same order. Each runs in its own child context; if any computation fails, all others are cancelled and the exception is propagated.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        @[inline, specialize #[]]

                        Launches a ContextAsync computation in the background, discarding its result.

                        The computation runs independently in the background in its own child context. The parent computation does not wait for background tasks to complete. This means that if the parent finishes its execution it will cause the cancellation of the background functions. See also disown for launching tasks that continue independently even after parent cancellation.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[inline, specialize #[]]

                          Launches a ContextAsync computation in the background, discarding its result. It's similar to background, but the child context is not automatically cancelled when the action completes. This allows the disowned computation to continue running independently, even if the parent context is cancelled. The child context will remain alive as long as the computation needs it. See also background for launching tasks that are cancelled when the parent finishes.

                          Equations
                          Instances For

                            Runs all computations concurrently and returns the first result. Each computation runs in its own child context; when the first completes successfully, all others are cancelled immediately.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              @[inline, specialize #[]]

                              Launches a ContextAsync computation as an asynchronous task with a forked child context. The child context is automatically cancelled when the task completes or fails.

                              Equations
                              Instances For
                                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.
                                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.

                                Returns a selector that completes when the current context is cancelled. This is useful for selecting on cancellation alongside other asynchronous operations.

                                Equations
                                Instances For