Skip to content

Commit 55f0b77

Browse files
authored
Add InvokeAsync with cancellation token overload to IJSRuntime (#1915)
Adds the InvokeAsync with cancellation token overload to IJSRuntime
1 parent 3537aca commit 55f0b77

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/JSInterop/Microsoft.JSInterop/ref/Microsoft.JSInterop.netstandard2.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public partial interface IJSInProcessRuntime : Microsoft.JSInterop.IJSRuntime
3232
}
3333
public partial interface IJSRuntime
3434
{
35+
System.Threading.Tasks.Task<TValue> InvokeAsync<TValue>(string identifier, System.Collections.Generic.IEnumerable<object> args, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
3536
System.Threading.Tasks.Task<TValue> InvokeAsync<TValue>(string identifier, params object[] args);
3637
}
3738
public partial class JSException : System.Exception

src/JSInterop/Microsoft.JSInterop/src/IJSRuntime.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
4+
using System.Collections.Generic;
5+
using System.Threading;
56
using System.Threading.Tasks;
67

78
namespace Microsoft.JSInterop
@@ -19,5 +20,15 @@ public interface IJSRuntime
1920
/// <param name="args">JSON-serializable arguments.</param>
2021
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
2122
Task<TValue> InvokeAsync<TValue>(string identifier, params object[] args);
23+
24+
/// <summary>
25+
/// Invokes the specified JavaScript function asynchronously.
26+
/// </summary>
27+
/// <typeparam name="TValue">The JSON-serializable return type.</typeparam>
28+
/// <param name="identifier">An identifier for the function to invoke. For example, the value <code>"someScope.someFunction"</code> will invoke the function <code>window.someScope.someFunction</code>.</param>
29+
/// <param name="args">JSON-serializable arguments.</param>
30+
/// <param name="cancellationToken">A cancellation token to signal the cancellation of the operation.</param>
31+
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
32+
Task<TValue> InvokeAsync<TValue>(string identifier, IEnumerable<object> args, CancellationToken cancellationToken = default);
2233
}
2334
}

src/JSInterop/Microsoft.JSInterop/test/JSRuntimeTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
7+
using System.Threading;
68
using System.Threading.Tasks;
79
using Xunit;
810

@@ -29,6 +31,9 @@ private class FakeJSRuntime : IJSRuntime
2931
{
3032
public Task<T> InvokeAsync<T>(string identifier, params object[] args)
3133
=> throw new NotImplementedException();
34+
35+
public Task<TValue> InvokeAsync<TValue>(string identifier, IEnumerable<object> args, CancellationToken cancellationToken = default) =>
36+
throw new NotImplementedException();
3237
}
3338
}
3439
}

0 commit comments

Comments
 (0)