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()
Types
| Type | Description |
|
Handle for a running bounded channel worker. Backed by Channel{T} instead of Handle{T}'s unbounded queue, so a producer that outruns the handler waits for room instead of growing memory without limit. |
|
|
Handle for a running channel worker. Post items for background processing. |
Functions and values
| Function or value |
Description
|
Full Usage:
ChannelWorker.start handler onError ct
Parameters:
'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.
|
Full Usage:
ChannelWorker.startBounded capacity handler onError ct
Parameters:
int
-
Maximum number of items the queue holds at once.
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: BoundedHandle<'T>
|
Starts a background worker that processes items sequentially from a queue of at most capacity items. If processing an item throws, onError is called and the worker continues. Cancelling ct abandons the queue: the worker stops as soon as the handler in progress returns, and items still queued may never be processed. Call Complete instead for a shutdown that drains them first.
|
TDesu.FSharp