You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently for those wishing to build a custom asynchronous activity, one must implement AsyncCodeActivity and work with the NetFx 3 async library, implementing BeginExecute and EndExecute. For many newer developers, this model is foreign and may be difficult to find adequate documentation of how to implement an activity using this model.
I would like to propose a new type, AsyncTaskCodeActivity, which instead exposes an abstract ExecuteAsync() method which returns a Task or Task<T> as appropriate. This can reuse much of the existing code available in the Windows Workflow Foundation library, such as AsyncCodeActivityContext.
Should System.ValueTask be used instead of System.Task? If a user wraps a MemoryStream or some other existing ValueTask that can return synchronously, ValueTask allows us to wrap the return value and avoid allocating. There are however a couple of potential downsides:
ValueTask/ValueTask<T> is less usable than its Task/Task<T> counterpart. However, since ValueTask/ValueTask<T> is best used in environments where it is simply going to be awaited, this makes it a particularly good candidate for UiPath. If it is being called outside of the UiPath code runner, then it is likely being done in a unit test by the developer who is building the activity. It will be on them to handle it appropriately.
ValueTask/ValueTask<T> is larger than Task/Task<T> when wrapping Task/Task<T>. This is a measurable difference in microbenchmarks, however for utilization in an environment like UiPath, I doubt it will make a big difference.
Is AsyncCodeActivity the correct target for extension? Should it instead extend Activity like AsyncCodeActivity does? The way my current implementation of AsyncTaskCodeActivity works, uses BeginExecute to start the task and uses a TaskCompletionSource to track the lifetime of the task. Then it uses EndExecute to return the value of the task. In the case of AsyncCodeActivity (without a return type), it uses an empty VoidResult struct as its result (since I can't use void as a return type). This type works similarly to MediatR's Unit type.
Should there be an interest in this change, I would be happy to submit a PR.
The text was updated successfully, but these errors were encountered:
Currently for those wishing to build a custom asynchronous activity, one must implement
AsyncCodeActivity
and work with the NetFx 3 async library, implementingBeginExecute
andEndExecute
. For many newer developers, this model is foreign and may be difficult to find adequate documentation of how to implement an activity using this model.I would like to propose a new type,
AsyncTaskCodeActivity
, which instead exposes an abstractExecuteAsync()
method which returns aTask
orTask<T>
as appropriate. This can reuse much of the existing code available in the Windows Workflow Foundation library, such asAsyncCodeActivityContext
.Proposed API Changes
Considerations/changes:
System.ValueTask
be used instead ofSystem.Task
? If a user wraps a MemoryStream or some other existing ValueTask that can return synchronously,ValueTask
allows us to wrap the return value and avoid allocating. There are however a couple of potential downsides:ValueTask
/ValueTask<T>
is less usable than itsTask
/Task<T>
counterpart. However, sinceValueTask
/ValueTask<T>
is best used in environments where it is simply going to be awaited, this makes it a particularly good candidate for UiPath. If it is being called outside of the UiPath code runner, then it is likely being done in a unit test by the developer who is building the activity. It will be on them to handle it appropriately.ValueTask
/ValueTask<T>
is larger thanTask
/Task<T>
when wrappingTask
/Task<T>
. This is a measurable difference in microbenchmarks, however for utilization in an environment like UiPath, I doubt it will make a big difference.AsyncCodeActivity
the correct target for extension? Should it instead extendActivity
likeAsyncCodeActivity
does? The way my current implementation ofAsyncTaskCodeActivity
works, uses BeginExecute to start the task and uses a TaskCompletionSource to track the lifetime of the task. Then it uses EndExecute to return the value of the task. In the case ofAsyncCodeActivity
(without a return type), it uses an emptyVoidResult
struct as its result (since I can't usevoid
as a return type). This type works similarly to MediatR'sUnit
type.Should there be an interest in this change, I would be happy to submit a PR.
The text was updated successfully, but these errors were encountered: