Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
737189d
rebase
pavelsavara Jan 16, 2024
85d6a0f
75123
pavelsavara Jan 17, 2024
08da5aa
more
pavelsavara Jan 17, 2024
c1bef65
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 17, 2024
f07acd5
more
pavelsavara Jan 17, 2024
ff63f69
add HTTP to MT smoke test
pavelsavara Jan 17, 2024
6697711
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 18, 2024
f3363db
wip
pavelsavara Jan 19, 2024
288b1c4
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 19, 2024
6de377c
feedback
pavelsavara Jan 19, 2024
91c748a
feedback
pavelsavara Jan 19, 2024
69ddae1
Update src/mono/browser/runtime/http.ts
pavelsavara Jan 19, 2024
4e67c24
feedback
pavelsavara Jan 19, 2024
a5f6aed
test cleanup
pavelsavara Jan 19, 2024
699a0d6
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 19, 2024
bef203e
fix
pavelsavara Jan 19, 2024
e6c8298
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 19, 2024
3bbefbd
fix
pavelsavara Jan 19, 2024
758243b
postpone RunContinuationsAsynchronously
pavelsavara Jan 19, 2024
a4136a4
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 19, 2024
7a95729
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 20, 2024
b924f1c
fix
pavelsavara Jan 20, 2024
3e989ca
ActiveIssue https://github.com/dotnet/runtime/issues/96628
pavelsavara Jan 20, 2024
440ee61
Merge branch 'main' into browser_jsimport_sc_dispatch
pavelsavara Jan 20, 2024
1056ab5
use TaskCompletionSource.TrySetFromTask
pavelsavara Jan 20, 2024
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
pavelsavara committed Jan 19, 2024
commit f3363db2b3bbb9eb38bbab0416a985645e3189d2
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal sealed class JSWebWorkerInstance<T> : IDisposable

public JSWebWorkerInstance(Func<Task<T>> bodyRes, CancellationToken cancellationToken)
{
_taskCompletionSource = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
_taskCompletionSource = new TaskCompletionSource<T>(TaskCreationOptions.DenyChildAttach | TaskCreationOptions.RunContinuationsAsynchronously | TaskCreationOptions.HideScheduler);
_thread = new Thread(ThreadMain);
_resultTask = null;
_cancellationToken = cancellationToken;
Expand All @@ -75,14 +75,19 @@ public Task<T> Start()
// give browser chance to load more threads
// until there at least one thread loaded, it doesn't make sense to `Start`
// because that would also hang, but in a way blocking the UI thread, much worse.
JavaScriptImports.ThreadAvailable().ContinueWith(t =>
JavaScriptImports.ThreadAvailable().ContinueWith(static (t, o) =>
{
var self = (JSWebWorkerInstance<T>)o!;
if (t.IsCompletedSuccessfully)
{
_thread.Start();
self._thread.Start();
}
return t;
}, _cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.FromCurrentSynchronizationContext());
if (t.IsCanceled)
{
throw new OperationCanceledException(self._cancellationToken);
}
throw t.Exception!;
}, this, _cancellationToken, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
}
else
{
Expand All @@ -97,16 +102,17 @@ private void ThreadMain()
{
if (_cancellationToken.IsCancellationRequested)
{
PropagateCompletionAndDispose(Task.FromException<T>(new OperationCanceledException(_cancellationToken)));
PropagateCompletionAndDispose(Task.FromCanceled<T>(_cancellationToken));
return;
}

// receive callback when the cancellation is requested
_cancellationRegistration = _cancellationToken.Register(() =>
_cancellationRegistration = _cancellationToken.Register(static (o) =>
{
var self = (JSWebWorkerInstance<T>)o!;
// this could be executing on any thread
PropagateCompletionAndDispose(Task.FromException<T>(new OperationCanceledException(_cancellationToken)));
});
self.PropagateCompletionAndDispose(Task.FromCanceled<T>(self._cancellationToken));
}, this);

// JSSynchronizationContext also registers to _cancellationToken
_jsSynchronizationContext = JSSynchronizationContext.InstallWebWorkerInterop(false, _cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public unsafe void ToManaged(out Task? value)
lock (ctx)
{
PromiseHolder holder = ctx.GetPromiseHolder(slot.GCHandle);
TaskCompletionSource tcs = new TaskCompletionSource(holder);
TaskCompletionSource tcs = new TaskCompletionSource(holder, TaskCreationOptions.DenyChildAttach | TaskCreationOptions.RunContinuationsAsynchronously);
ToManagedCallback callback = (JSMarshalerArgument* arguments_buffer) =>
{
if (arguments_buffer == null)
Expand Down Expand Up @@ -98,7 +98,7 @@ public unsafe void ToManaged<T>(out Task<T>? value, ArgumentToManagedCallback<T>
lock (ctx)
{
var holder = ctx.GetPromiseHolder(slot.GCHandle);
TaskCompletionSource<T> tcs = new TaskCompletionSource<T>(holder);
TaskCompletionSource<T> tcs = new TaskCompletionSource<T>(holder, TaskCreationOptions.DenyChildAttach | TaskCreationOptions.RunContinuationsAsynchronously);
ToManagedCallback callback = (JSMarshalerArgument* arguments_buffer) =>
{
if (arguments_buffer == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--

<Import Condition="'$(TargetOS)' == 'browser'" Project="$(CommonTestPath)System/Net/Prerequisites/LocalEchoServer.props" />
-->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,33 @@ namespace System.Runtime.InteropServices.JavaScript.Tests

public class WebWorkerTest : IAsyncLifetime
{
const int TimeoutMilliseconds = 300;
const int TimeoutMilliseconds = 5000;

public static bool _isWarmupDone;

public async Task InitializeAsync()
{
if (_isWarmupDone)
{
return;
}
await Task.Delay(500);
_isWarmupDone = true;
}

public Task DisposeAsync() => Task.CompletedTask;

#region Executors

private CancellationTokenSource CreateTestCaseTimeoutSource()
{
var cts = new CancellationTokenSource(TimeoutMilliseconds);
cts.Token.Register(() => {
Console.WriteLine($"Unexpected test case timeout at {DateTime.Now.ToString("u")} ManagedThreadId:{Environment.CurrentManagedThreadId}");
});
return cts;
}

public static IEnumerable<object[]> GetTargetThreads()
{
return Enum.GetValues<ExecutorType>().Select(type => new object[] { new Executor(type) });
Expand Down Expand Up @@ -677,19 +700,5 @@ await Assert.ThrowsAsync<TaskCanceledException>(async () =>
}

#endregion

public static bool _isWarmupDone;

public async Task InitializeAsync()
{
if (_isWarmupDone)
{
return;
}
await Task.Delay(500);
_isWarmupDone = true;
}

public Task DisposeAsync() => Task.CompletedTask;
}
}