LanguageExt.Core

LanguageExt.Core Async

Contents

Sub modules

AsyncEnumerable

class Async Source #

The Async module helps transition away from the Task / async / await world and into one where awaiting is the default setting for concurrent programming and branching/forking is the thing we do the least.

The Async.await function will convert a Task<A> into an A by waiting for the Task to complete; it will yield the thread whilst it's waiting (to play nice with other tasks in the task-pool). This is just like the regular await keyword without all the ceremony and colouring of methods.

Async.fork lifts a function into an IO monad, forks it, and then runs the IO monad returning a ForkIO object. The forked operation continues to run in parallel. The ForkIO object contains two properties: Await and Cancel that be used to either await the result or cancel the operation.

These two functions remove the need for methods that are 'tainted' with Task or async / await mechanics and assume that the thing we will do the most with asynchronous code is to await it.

This module shouldn't be needed too much, as the IO monad is where most of the asynchrony should be. But, when converting from existing async/await code, or if you're coming from language-ext v4, or earlier, where there was lots of *Async methods in the key types, then this module will help ease the transition.

Methods

method A await <A> (Task<A> operation) Source #

Simple awaiter that yields the thread whilst waiting. Allows for the Task to be used with synchronous code without blocking any threads for concurrent processing.

Parameters

type A

Bound value type

param operation

Task to await

returns

Result of the task, TaskCanceledException, or any exception raised by the task

method ForkIO<A> fork <A> (Func<A> operation, TimeSpan timeout = default) Source #

Async.fork lifts a function into an IO monad, forks it, and then runs the IO monad returning the ForkIO object. The forked operation continues to run in parallel. The ForkIO object contains two properties: Await and Cancel that be used to either await the result or cancel the operation.

Parameters

type A

Bound value type

param operation

Operation to fork

param timeout

Optional timeout

returns

The ForkIO object contains two properties: Await and Cancel that be used to either await the result or cancel the operation.

method ForkIO<A> fork <A> (Func<Task<A>> operation, TimeSpan timeout = default) Source #

Async.fork lifts a function into an IO monad, forks it, and then runs the IO monad returning the ForkIO object. The forked operation continues to run in parallel. The ForkIO object contains two properties: Await and Cancel that be used to either await the result or cancel the operation.

Parameters

type A

Bound value type

param operation

Operation to fork

param timeout

Optional timeout

returns

The ForkIO object contains two properties: Await and Cancel that be used to either await the result or cancel the operation.