dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

[Workflows] Expose CancellationToken as part of RunAsync

Open clintsinger opened this issue 1 year ago • 3 comments

Describe the feature

Currently the CancellationToken isn't exposed by the RunAsync abstract method. Traditionally, async methods include the token to be passed to subsequent async calls.

While there isn't currently any support for cancellation tokens, there is discussion about introducing them in the future. Since including it as part of the method signature would be a breaking change, it would make sense to introduce it at this time, during the beta period, in preparation for future use. A CancellationToken.None can be passed for the time being.

The run method signatures should look like the following for workflows and activities respectively, with the interfaces also being modified accordingly.

public abstract class Workflow<TInput, TOutput> : IWorkflow
{
  public abstract Task<TOutput> RunAsync(WorkflowContext context, TInput input, CancellationToken cancellationToken);
}

public abstract class WorkflowActivity<TInput, TOutput> : IWorkflowActivity
{
  public abstract Task<TOutput> RunAsync(WorkflowActivityContext context, TInput input), CancellationToken cancellationToken);
}

clintsinger avatar Jan 12 '24 19:01 clintsinger

Yes Please

AceHack avatar Feb 07 '24 12:02 AceHack

cc @cgillum can you put a label for priority on this issue?

cicoyle avatar Sep 12 '24 19:09 cicoyle

For the sake of not creating APIs that we hope to implement (the future often plays out differently than how we expect), I would prefer we plan to add cancellation token support as a property of the context object rather than as a parameter in RunAsync. This would be a non-breaking change that we can implement when we're ready to do so.

For that reason, I suggest we make this a P2 for 1.15 with the intent of actually implementing cancellation (at least for workflow activities) rather than hardcoding it to CancellationToken.None.

cgillum avatar Sep 13 '24 00:09 cgillum