Repository navigation
Conversation
When set (UNITASK_NETCORE only, default false), the async method builders capture the ExecutionContext at each await, the pooled runners resume inside ExecutionContext.Run with it, and Start runs the code before the first await inside AsyncTaskMethodBuilder.Start. An async UniTask method then treats the context as async Task does, so AsyncLocal values survive an await. Unset, and in Unity builds, behavior is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an opt-in setting so
async UniTaskmethods on .NET restore the ExecutionContext asasync Taskdoes, lettingAsyncLocalvalues survive an await. It is off by default, so nothing changes unless you set it.Why
async UniTaskmethod losesAsyncLocalstate (ILogger scopes in Microsoft.Extensions.Logging.ILogger.BeginScope does not carry scope. #363, Serilog'sLogContext, a per-request unit of work), or runs with whatever context the completing thread carries.What changes
UniTaskScheduler.FlowExecutionContext, underUNITASK_NETCOREonly, defaultfalse.ExecutionContext.Run. A runner returned to the pool drops its context.Startruns the code before the first await insideAsyncTaskMethodBuilder.Start, so a write there stays in the method, as withasync Task.#if UNITASK_NETCORE.Cost
Each call has one suspending await, resumed inline, with an
AsyncLocalset. 2M calls, best of 5, .NET 8.0.19, Apple M4 Pro:async Task<int>async UniTask<int>async UniTaskTests
ExecutionContextTesthas 5 tests and runs with the setting on, in a non-parallel collection. With the setting off, 4 of them fail. The 5th guards theStartchange.UniTask.NetCoreTestssuite: 342/342.🤖 Generated with Claude Code