Header menu logo TDesu.FSharp

ChannelWorker Module

Generic background worker that processes items sequentially from an internal queue. Fault-tolerant: errors in handlers are reported via callback without crashing the worker. Stops gracefully on cancellation.

Example

 use cts = new CancellationTokenSource()
 let worker = ChannelWorker.start (fun msg -> task { printfn "%s" msg }) (fun ex -> eprintfn "%A" ex) cts.Token
 worker.Post("hello")
 worker.Post("world")
 cts.Cancel()
val cts: obj
val worker: obj
val task: TaskBuilder
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val eprintfn: format: Printf.TextWriterFormat<'T> -> 'T

Types

Type Description

Handle<'T>

Handle for a running channel worker. Post items for background processing.

Functions and values

Function or value Description

ChannelWorker.start handler onError ct

Full Usage: ChannelWorker.start handler onError ct

Parameters:
    handler : 'T -> Task - Async function to process each item.
    onError : exn -> unit - Called when handler throws. If this also throws, the exception is swallowed.
    ct : CancellationToken - Cancellation token to stop the worker.

Returns: Handle<'T>

Starts a background worker that processes items sequentially. If processing an item throws, onError is called and the worker continues.

Items posted after cancellation are silently ignored. Items already queued at cancellation time may not be processed.

handler : 'T -> Task

Async function to process each item.

onError : exn -> unit

Called when handler throws. If this also throws, the exception is swallowed.

ct : CancellationToken

Cancellation token to stop the worker.

Returns: Handle<'T>

Type something to start searching.