Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Temporalio/Activities/ActivityDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private ActivityDefinition(
public string? Name { get; private init; }

/// <summary>
/// Gets the return type for the definition. This may be a Task for async activities. This
/// is currently unused (callers are expected to provide the return type as needed).
/// Gets the return type for the definition. This may be a Task for async activities. When
/// it is a non-generic Task, the activity completes with no result.
/// </summary>
public Type ReturnType { get; private init; }

Expand Down Expand Up @@ -84,7 +84,7 @@ public static ActivityDefinition Create(Delegate del)
/// Create an activity definition manually from the given values.
/// </summary>
/// <param name="name">Name to use for the activity or null for dynamic.</param>
/// <param name="returnType">Return type of the activity. This is currently unused.</param>
/// <param name="returnType">Return type of the activity. A non-generic Task means no result.</param>
/// <param name="parameterTypes">Parameter types for the invoker.</param>
/// <param name="requiredParameterCount">Minimum number of parameters that must be provided
/// to the invoker.</param>
Expand Down Expand Up @@ -212,9 +212,10 @@ public static IReadOnlyCollection<ActivityDefinition> CreateAll(Type type, objec
if (result is Task resultTask)
{
await resultTask.ConfigureAwait(false);
// We have to use reflection to extract value if it's a Task<>
// We have to use reflection to extract value if it's a Task<>, but not if the
// activity is declared as a non-generic Task
var resultTaskType = resultTask.GetType();
if (resultTaskType.IsGenericType)
if (ReturnType != typeof(Task) && resultTaskType.IsGenericType)
{
result = resultTaskType.GetProperty("Result")!.GetValue(resultTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ public async Task InvokeAsync_AsyncDelegate_CanInvoke()
await ActivityDefinition.Create(act).InvokeAsync(new object?[] { 123 }));
}

[Fact]
public async Task InvokeAsync_TaskDelegateReturningGenericTask_HasNoResult()
{
var act = [Activity("MyActivity")] Task (int param) => Task.FromResult(param + 5);
Assert.Equal(
ValueTuple.Create(),
await ActivityDefinition.Create(act).InvokeAsync(new object?[] { 123 }));
}

[Fact]
public async Task InvokeAsync_ManualInvoker_IsCalled()
{
Expand Down
Loading