PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.Run Class Reference

Provides convenience wrapper functions to run small bits of work in parallel threads, not tasks. No async/await, no Tasks (unless you want to return them and await them yourself). No TPL. No handbrakes. No magic context. No guarantees, except that your work will be executed. May make the host machine very tired. More...

Static Public Member Functions

static Exception[] InParallel (Action first, Action second, params Action[] more)
 Run all actions in parallel, returning any captured exceptions.
static Exception[] InParallel (int maxDegreeOfParallelism, Action first, Action second, params Action[] more)
 Run all actions in parallel, with the provided max degree of parallelism, returning any captured exceptions.
static WorkResult< T >[] InParallel< T > (Func< T > first, Func< T > second, params Func< T >[] more)
 Run all functions in parallel, returning all results / exceptions.
static WorkResult< T >[] InParallel< T > (int maxDegreeOfParallelism, Func< T > first, Func< T > second, params Func< T >[] more)
 Run all provided functions with the max degree of parallelism, returning all results / exceptions.
static Exception[] InParallel (int maxDegreeOfParallelism, IEnumerable< Action > actions)
 Run a bunch of actions in parallel.
static void Once (ref bool gateFlag, Action toRun)
 Runs the action once and once only.
static T Until< T > (Func< T, bool > validator, Func< T > generator)
 Run the generator until the validator is satisfied and return the result.
static T Until< T > (Func< T, bool > validator, Func< T, T > generator)
 Run the generator until the validator is satisfied and return the result.
static async Task< T > Until< T > (Func< T, bool > validator, Func< T, Task< T > > generator)
 Run the generator until the validator is satisfied and return the result.
static async Task< T > Until< T > (Func< T, bool > validator, Func< Task< T > > generator)
 Run the generator until the validator is satisfied and return the result.
static async Task< T > Until< T > (Func< T, Task< bool > > validator, Func< T, T > generator)
 Run the generator until the validator is satisfied and return the result.
static async Task< T > Until< T > (Func< T, Task< bool > > validator, Func< T, Task< T > > generator)
 Run the generator until the validator is satisfied and return the result.
static void WithTimeout (int timeoutMs, Action logic)
static void WithTimeout (TimeSpan timeout, Action logic)
static async Task WithTimeoutAsync (int timeoutMs, Func< Task > logic)
static async Task WithTimeoutAsync (TimeSpan timeout, Func< Task > logic)
static async Task WithTimeoutAsync (int timeoutMs, Func< CancellationToken, Task > logic)
static async Task WithTimeoutAsync (TimeSpan timeout, Func< CancellationToken, Task > logic)
static async Task< T > WithTimeoutAsync< T > (int timeoutMs, Func< CancellationToken, Task< T > > logic)
static async Task< T > WithTimeoutAsync< T > (TimeSpan timeout, Func< CancellationToken, Task< T > > logic)
static async Task< T > WithTimeoutAsync< T > (TimeSpan timeout, Func< CancellationToken, Task< T > > logic, ErrorStrategies errorStrategy)

Detailed Description

Provides convenience wrapper functions to run small bits of work in parallel threads, not tasks. No async/await, no Tasks (unless you want to return them and await them yourself). No TPL. No handbrakes. No magic context. No guarantees, except that your work will be executed. May make the host machine very tired.

Provides a convenience wrapper to time-out a long-running operation which has taken too long.

Provides Run.Until, a convenience mechanism to run a bit of logic until some condition is met.

Member Function Documentation

◆ InParallel() [1/3]

Exception[] PeanutButter.Utils.Run.InParallel ( Action first,
Action second,
params Action[] more )
static

Run all actions in parallel, returning any captured exceptions.

Parameters
first
second
more

◆ InParallel() [2/3]

Exception[] PeanutButter.Utils.Run.InParallel ( int maxDegreeOfParallelism,
Action first,
Action second,
params Action[] more )
static

Run all actions in parallel, with the provided max degree of parallelism, returning any captured exceptions.

Parameters
maxDegreeOfParallelism
first
second
more

◆ InParallel() [3/3]

Exception[] PeanutButter.Utils.Run.InParallel ( int maxDegreeOfParallelism,
IEnumerable< Action > actions )
static

Run a bunch of actions in parallel.

Parameters
maxDegreeOfParallelism
actions
Returns

◆ InParallel< T >() [1/2]

WorkResult< T >[] PeanutButter.Utils.Run.InParallel< T > ( Func< T > first,
Func< T > second,
params Func< T >[] more )
static

Run all functions in parallel, returning all results / exceptions.

Parameters
first
second
more

◆ InParallel< T >() [2/2]

WorkResult< T >[] PeanutButter.Utils.Run.InParallel< T > ( int maxDegreeOfParallelism,
Func< T > first,
Func< T > second,
params Func< T >[] more )
static

Run all provided functions with the max degree of parallelism, returning all results / exceptions.

Parameters
maxDegreeOfParallelism
first
second
more

◆ Once()

void PeanutButter.Utils.Run.Once ( ref bool gateFlag,
Action toRun )
static

Runs the action once and once only.

Parameters
gateFlag
toRun

◆ Until< T >() [1/6]

T PeanutButter.Utils.Run.Until< T > ( Func< T, bool > validator,
Func< T > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ Until< T >() [2/6]

T PeanutButter.Utils.Run.Until< T > ( Func< T, bool > validator,
Func< T, T > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ Until< T >() [3/6]

async Task< T > PeanutButter.Utils.Run.Until< T > ( Func< T, bool > validator,
Func< T, Task< T > > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ Until< T >() [4/6]

async Task< T > PeanutButter.Utils.Run.Until< T > ( Func< T, bool > validator,
Func< Task< T > > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ Until< T >() [5/6]

async Task< T > PeanutButter.Utils.Run.Until< T > ( Func< T, Task< bool > > validator,
Func< T, T > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ Until< T >() [6/6]

async Task< T > PeanutButter.Utils.Run.Until< T > ( Func< T, Task< bool > > validator,
Func< T, Task< T > > generator )
static

Run the generator until the validator is satisfied and return the result.

Parameters
validator
generator
Template Parameters
T
Returns

◆ WithTimeout() [1/2]

void PeanutButter.Utils.Run.WithTimeout ( int timeoutMs,
Action logic )
static
Parameters
timeoutMs
logic

◆ WithTimeout() [2/2]

void PeanutButter.Utils.Run.WithTimeout ( TimeSpan timeout,
Action logic )
static
Parameters
timeout
logic

◆ WithTimeoutAsync() [1/4]

async Task PeanutButter.Utils.Run.WithTimeoutAsync ( int timeoutMs,
Func< CancellationToken, Task > logic )
static
Parameters
timeoutMs
logic
Returns

◆ WithTimeoutAsync() [2/4]

async Task PeanutButter.Utils.Run.WithTimeoutAsync ( int timeoutMs,
Func< Task > logic )
static
Parameters
timeoutMs
logic

◆ WithTimeoutAsync() [3/4]

async Task PeanutButter.Utils.Run.WithTimeoutAsync ( TimeSpan timeout,
Func< CancellationToken, Task > logic )
static
Parameters
timeout
logic
Returns

◆ WithTimeoutAsync() [4/4]

async Task PeanutButter.Utils.Run.WithTimeoutAsync ( TimeSpan timeout,
Func< Task > logic )
static
Parameters
timeout
logic

◆ WithTimeoutAsync< T >() [1/3]

async Task< T > PeanutButter.Utils.Run.WithTimeoutAsync< T > ( int timeoutMs,
Func< CancellationToken, Task< T > > logic )
static
Parameters
timeoutMs
logic

◆ WithTimeoutAsync< T >() [2/3]

async Task< T > PeanutButter.Utils.Run.WithTimeoutAsync< T > ( TimeSpan timeout,
Func< CancellationToken, Task< T > > logic )
static
Parameters
timeout
logic

◆ WithTimeoutAsync< T >() [3/3]

async Task< T > PeanutButter.Utils.Run.WithTimeoutAsync< T > ( TimeSpan timeout,
Func< CancellationToken, Task< T > > logic,
ErrorStrategies errorStrategy )
static
Parameters
timeout
logic
errorStrategy

The documentation for this class was generated from the following files:
  • source/Utils/PeanutButter.Utils/Run.InParallel.cs
  • source/Utils/PeanutButter.Utils/Run.Once.cs
  • source/Utils/PeanutButter.Utils/Run.Until.cs
  • source/Utils/PeanutButter.Utils/Run.WithTimeout.cs