Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 79f6ab4

Browse files
author
Michael
committed
Implementation of Task.FromResult<TResult>(TResult result)
1 parent 39e2768 commit 79f6ab4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

JSIL.Libraries/Includes/Bootstrap/Async/Classes/System.Threading.Tasks.Task.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ JSIL.ImplementExternals("System.Threading.Tasks.Task", function ($) {
137137
return tcs.Task;
138138
}
139139
);
140+
141+
$.Method({ Static: true, Public: true }, "FromResult",
142+
new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Tasks.Task`1", ["!!0"]), ["!!0"], ["TResult"]),
143+
function(TResult, result) {
144+
var task = new ($jsilcore.System.Threading.Tasks.Task$b1.Of(TResult));
145+
task.status = $jsilcore.System.Threading.Tasks.TaskStatus.RanToCompletion;
146+
task.result = result;
147+
return task;
148+
}
149+
);
140150
});
141151

142152
JSIL.ImplementExternals("System.Threading.Tasks.Task`1", function ($) {
@@ -263,6 +273,10 @@ JSIL.MakeType({
263273
new JSIL.MethodSignature($jsilcore.TypeRef("System.Runtime.CompilerServices.TaskAwaiter"), [], [])
264274
);
265275

276+
$.ExternalMethod({ Static: true, Public: true }, "FromResult",
277+
new JSIL.MethodSignature($jsilcore.TypeRef("System.Threading.Tasks.Task`1", ["!!0"]), ["!!0"], ["TResult"])
278+
);
279+
266280
$.Property({ Static: false, Public: true }, "Exception", $jsilcore.TypeRef("System.AggregateException"));
267281

268282
$.Property({ Static: false, Public: true, Virtual: true }, "IsCompleted", $.Boolean);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
public static class Program {
5+
public static void Main (string[] args)
6+
{
7+
var task = Task.FromResult(new A(true));
8+
Console.WriteLine(task.GetType().FullName);
9+
Console.WriteLine(task.Status);
10+
Console.WriteLine(task.Result.Value ? "true" : "false");
11+
}
12+
}
13+
14+
public class A
15+
{
16+
public readonly bool Value;
17+
18+
public A(bool value)
19+
{
20+
Value = value;
21+
}
22+
}

Tests/SimpleTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<None Include="SimpleTestCases\ArrayCast.cs" />
143143
<None Include="SimpleTestCases\Issue913.cs" />
144144
<None Include="SimpleTestCases\BoxNumeric_Issue981.cs" />
145+
<None Include="SimpleTestCases\Task_FromResult.cs" />
145146
<None Include="SimpleTestCases\NullableUnary_Issue997.cs" />
146147
<None Include="SimpleTestCasesForTranslatedBcl\Issue1008_MethodReturnType.cs" />
147148
<None Include="SimpleTestCases\GetTypeFromAssembly_Issue1035.cs" />

0 commit comments

Comments
 (0)