Logo Orsak

BackgroundWorker Module

Hosts long-running effects as ASP.NET Core background services, with AddEffectWorker.

Types

Type Description

EffectfulBackgroundService<'r, 'e>

The hosted service AddEffectWorker registers: it runs the worker effect with Effect.forever, starting it again whenever it fails, until it completes successfully or the host stops.

Type extensions

Type extension Description

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : IServiceProvider -> CancellationToken -> 'r - Creates the environment from the application's services and the host's stopping token
    work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the application's services and the host's stopping token. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : IServiceProvider -> CancellationToken -> 'r

Creates the environment from the application's services and the host's stopping token

work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection
Example

 let processMessages (ct: CancellationToken) = eff {
     while not ct.IsCancellationRequested do
         let! message = Queue.receive ()
         do! handle message
 }

 builder.Services.AddEffectWorker((fun services ct -> createEnv services ct), processMessages)
val processMessages: ct: 'a -> 'b
val ct: 'a

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : CancellationToken -> 'r - Creates the environment from the host's stopping token
    work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the host's stopping token. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : CancellationToken -> 'r

Creates the environment from the host's stopping token

work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : IServiceProvider -> 'r - Creates the environment from the application's services
    work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the application's services. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : IServiceProvider -> 'r

Creates the environment from the application's services

work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    provider : 'r - The environment
    work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is the one given. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

provider : 'r

The environment

work : Expr<(CancellationToken -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, taking the host's stopping token and returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : IServiceProvider -> CancellationToken -> 'r - Creates the environment from the application's services and the host's stopping token
    work : Expr<(unit -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the application's services and the host's stopping token. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : IServiceProvider -> CancellationToken -> 'r

Creates the environment from the application's services and the host's stopping token

work : Expr<(unit -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : CancellationToken -> 'r - Creates the environment from the host's stopping token
    work : Expr<(unit -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the host's stopping token. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : CancellationToken -> 'r

Creates the environment from the host's stopping token

work : Expr<(unit -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    f : IServiceProvider -> 'r - Creates the environment from the application's services
    work : Expr<(unit -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is created from the application's services. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

f : IServiceProvider -> 'r

Creates the environment from the application's services

work : Expr<(unit -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection

this.AddEffectWorker

Full Usage: this.AddEffectWorker

Parameters:
    provider : 'r - The environment
    work : Expr<(unit -> Effect<'r, unit, 'e>)> - The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection
Type parameters: 'r, 'e

Registers a hosted service that runs an effect in the background for the lifetime of the application. The environment is the one given. The effect is started again whenever it fails, and the worker stops when it completes successfully, so it is typically written as a loop.

Extended Type: IServiceCollection

provider : 'r

The environment

work : Expr<(unit -> Effect<'r, unit, 'e>)>

The worker: a function, passed directly so that its name can name the worker's logger, returning the effect to run

Returns: IServiceCollection

Type something to start searching.