Method Capture
- Namespace
- Millrace.Invocations
- Assembly
- Millrace.dll
Capture<T>(Expression<Func<T, Task>>, JsonSerializerOptions)
Captures a call expression into the form a worker can replay later, in another process.
public static JobInvocation Capture<T>(Expression<Func<T, Task>> call, JsonSerializerOptions json) where T : class
Parameters
callExpression<Func<T, Task>>jsonJsonSerializerOptions
Returns
Type Parameters
T
Remarks
Arguments are evaluated here, at enqueue time, and stored as JSON — the job carries values, never the closure that produced them. That is the whole reason for the "pass ids, not entities" guidance: whatever is captured is what runs, however stale it has become by the time it does.
The call shapes 0.1 does not support are rejected here rather than at execution. The same mistake caught later would surface minutes afterwards, in a different process, as a failing job rather than a failing enqueue — so the check is worth doing while the caller is still on the stack.
A CancellationToken parameter is captured as a placeholder and filled in with the job's execution token at invoke time; whatever token the enqueuing code held is not the one that should cancel the work.
Exceptions
- ArgumentException
callis not a single instance method call made directly on the service parameter, or one of its arguments reads that parameter — which cannot work, since the service instance does not exist until the job runs.- NotSupportedException
The method is generic, returns ValueTask, or has a ref, in or out parameter.