ORLEANS0205: Await, schedule, or post durable task definitions
| Property | Value |
|---|---|
| Severity | Error |
| Category | Usage |
| Code fix | None |
Code calls a method which returns DurableTask or DurableTask<TResult>, or configures the result with WithId, Detached, or Shielded, and discards the value without awaiting, scheduling, or posting it:
public async DurableTask FulfillAsync(string customer){ await Pack().WithId("pack");
// Creates a definition and discards it: the receipt never sends. SendReceipt(customer);}The C# compiler also reports CS4014 for some of these statements in async methods. ORLEANS0205 also covers definitions which are assigned to a discard, _ = SendReceipt(customer);, configurations, such as SendReceipt(customer).WithId("receipt");, and locals which hold a definition that no code awaits, schedules, posts, returns, or passes on, such as var receipt = SendReceipt(customer); followed by return;. A local which another local only renames or configures, such as var named = receipt.WithId("receipt");, counts as unused too, and a local which code assigns again isn’t reported.
Rule description
Section titled “Rule description”A durable task is cold: calling its method creates a definition, and configuring the definition returns a configuration of it. Neither starts the task. The task runs when the definition is awaited, scheduled with ScheduleAsync, or started with Post. A discarded definition never runs, so the receipt in the example is never sent, and no error reports it.
For the ways to start a task, see Starting and observing tasks.
How to fix violations
Section titled “How to fix violations”Await the definition to run the task and continue with its result:
public async DurableTask FulfillAndSendAsync(string customer){ await Pack().WithId("pack"); await SendReceipt(customer).WithId("receipt");}Schedule it and await the handle later to run it concurrently with other work. ScheduleAsync returns the task’s handle once its host has accepted it:
public async DurableTask FulfillWhileSendingAsync(string customer){ // Starts the receipt and continues; the execution owns it and observes its outcome before it returns. var receipt = await SendReceipt(customer).WithId("receipt").ScheduleAsync(); await Pack().WithId("pack"); await receipt;}Post it to stage the start with the execution’s next journal write, without an await. Post returns the handle, which the execution can await later:
public async DurableTask FulfillAndPostAsync(string customer){ await Pack().WithId("pack");
// Stages the receipt with the execution's next journal write, without waiting for it to start. var receipt = SendReceipt(customer).WithId("receipt").Post(); await receipt;}A durable grain call which the starter doesn’t wait for runs as a detached task, .Detached().Post(), which runs independently of its starter.
When to suppress
Section titled “When to suppress”Suppress the diagnostic where a definition is passed to code which starts it later, through a path which the analyzer doesn’t follow.
