Class RDWebMachinePool
- Namespace
- RDCore.Web.Machines
- Assembly
- RDCore.Web.dll
The machines of an RD-VBA program: each request borrows an idle one, runs on it alone, and returns it. A request that finds none idle waits for one, without holding a thread.
public sealed class RDWebMachinePool : IAsyncDisposable
- Inheritance
-
RDWebMachinePool
- Implements
- Inherited Members
Remarks
- The pool makes MinMachines machines when it starts, and more when a request finds none idle, up to MaxMachines. A pool of one machine serves its requests one at a time, in the order they arrive.
- After each request the pool resets the machine, then makes it idle. It recycles the machine (disposes it, and makes another) after RecycleAfter requests, after an invocation that was interrupted, did not end, or threw, and after a reset that did not complete.
- A request that waits for a machine past RequestTimeout answers Refused. One that runs past it is cancelled. A machine that has not stopped StopTimeout after its request's deadline, or after its reset's, is abandoned: its request answers Interrupted, the pool makes another machine, and it disposes the abandoned one if it ever ends.
Properties
Abandoned
How many machines the pool abandoned because they did not stop.
public int Abandoned { get; }
Property Value
Size
How many machines the pool holds: idle, serving a request, or being made. An abandoned machine is not counted.
public int Size { get; }
Property Value
Methods
DisposeAsync()
Disposes the pool: it takes no more requests, and disposes each machine, now when it is idle, or when it ends its request. The pool does not dispose the program: its owner does, once the pool is disposed.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that completes when the idle machines and the pool's own work have ended.
InvokeAsync(ProgramInvocation, CancellationToken)
Runs the invocation on an idle machine, once there is one, and returns the machine to the pool when it ends.
public Task<ProgramInvocationResult> InvokeAsync(ProgramInvocation invocation, CancellationToken cancellationToken)
Parameters
invocationProgramInvocationThe procedure, and its arguments.
cancellationTokenCancellationTokenCancels the wait for a machine, and the invocation: the request was aborted.
Returns
- Task<ProgramInvocationResult>
What the machine answered; Refused when no machine was idle before the request's deadline, and Interrupted when the machine did not stop after it.
Exceptions
- OperationCanceledException
cancellationTokenwas cancelled before a machine was idle.- ObjectDisposedException
The pool is disposed.
StartAsync(IComposedProgram, RDWebMachinePoolOptions, CancellationToken, TimeProvider?)
Starts a pool: it makes its MinMachines machines, all of them idle.
public static Task<RDWebMachinePool> StartAsync(IComposedProgram program, RDWebMachinePoolOptions options, CancellationToken cancellationToken, TimeProvider? timeProvider = null)
Parameters
programIComposedProgramThe program whose machines the pool makes, each a session of its own. The pool does not dispose it.
optionsRDWebMachinePoolOptionsThe pool's size and limits.
cancellationTokenCancellationTokenCancels the start.
timeProviderTimeProviderThe clock of the pool's deadlines; System by default.
Returns
- Task<RDWebMachinePool>
The pool, started.
Exceptions
- ArgumentOutOfRangeException
MaxMachines is less than 1, MinMachines is negative or more than the maximum, RecycleAfter is less than 1, or a timeout is not positive.