Skip to content
Open
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions cli/beamable.common/Runtime/Promise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,23 @@ void ICriticalNotifyCompletion.UnsafeOnCompleted(Action continuation)

void INotifyCompletion.OnCompleted(Action continuation)
{
#if DISABLE_THREADING
((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation);
#else
// Mirror TaskAwaiter.OnCompleted: flow ExecutionContext so AsyncLocal
// values set by the caller survive the await and are restored on the
// thread that resolves the promise.
var capturedContext = System.Threading.ExecutionContext.Capture();
if (capturedContext == null)
{
((ICriticalNotifyCompletion)this).UnsafeOnCompleted(continuation);
return;
}
((ICriticalNotifyCompletion)this).UnsafeOnCompleted(() =>
{
System.Threading.ExecutionContext.Run(capturedContext, s => ((Action)s)(), continuation);
});
Comment thread
Leinnan marked this conversation as resolved.
#endif
}

/// <summary>
Expand Down
Loading