Skip to content

Commit

Permalink
Fix Dashboard UI to display "await" keyword on all task-like methods
Browse files Browse the repository at this point in the history
Previously "await" keyword was added only for methods backed by async state machine.

Fixes #1418
  • Loading branch information
odinserj committed Jun 20, 2019
1 parent b53d30c commit dfee307
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Hangfire.Core/Dashboard/JobMethodCallRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Threading;
using Hangfire.Common;
using Hangfire.Dashboard.Resources;
using Hangfire.Processing;

namespace Hangfire.Dashboard
{
Expand Down Expand Up @@ -65,7 +66,8 @@ public static NonEscapedString Render(Job job)
builder.AppendLine();
}

if (job.Method.GetCustomAttribute<AsyncStateMachineAttribute>() != null)
if (job.Method.GetCustomAttribute<AsyncStateMachineAttribute>() != null ||
job.Method.ReturnType.IsTaskLike(out _))
{
builder.Append($"{WrapKeyword("await")} ");
}
Expand Down
3 changes: 2 additions & 1 deletion src/Hangfire.Core/Processing/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public static bool IsTaskLike(this Type type, out Func<object, Task> getTaskFunc
// This method can be replaced with wrapping in a custom awaiter like
// in ASP.NET Core, but this step requires using the `await` keyword
// to get the result, so can be implemented only in future.
if (typeInfo.FullName.StartsWith("System.Threading.Tasks.ValueTask", StringComparison.Ordinal))
if (typeInfo.FullName != null &&
typeInfo.FullName.StartsWith("System.Threading.Tasks.ValueTask", StringComparison.Ordinal))
{
var asTask = type.GetRuntimeMethod("AsTask", EmptyTypes);

Expand Down

0 comments on commit dfee307

Please sign in to comment.