Skip to content

Commit

Permalink
Async JavascriptBinding - Return null instead of empty object for asy…
Browse files Browse the repository at this point in the history
…nc Task methods

Resolves #3980
  • Loading branch information
amaitland committed Feb 10, 2022
1 parent 870dbb5 commit bedccd2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CefSharp/Internals/ConcurrentMethodRunnerQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace CefSharp.Internals
/// </summary>
public class ConcurrentMethodRunnerQueue : IMethodRunnerQueue
{
private static Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult");
private readonly IJavascriptObjectRepositoryInternal repository;
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

Expand Down Expand Up @@ -77,10 +78,14 @@ public void Enqueue(MethodInvocation methodInvocation)
{
if (t.Status == TaskStatus.RanToCompletion)
{
//TODO: Use resultTask.GetAwaiter().GetResult() instead
//We use some reflection to get the Result
//If someone has a better way of doing this then please submit a PR
result.Result = resultType.GetProperty("Result").GetValue(resultTask);

if (result.Result != null && result.Result.GetType() == VoidTaskResultType)
{
result.Result = null;
}
}
else
{
Expand Down

0 comments on commit bedccd2

Please sign in to comment.