Add UnwrapIfPromiseAsync extension method for non-blocking promise resolution#2298
Merged
Merged
Conversation
Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add async version of UnwrapIfPromise for JsValue
Add Mar 1, 2026
UnwrapIfPromiseAsync extension method for non-blocking promise resolution
Collaborator
|
@copilot update readme to contain both evaluateasync and this new feature. |
…sync and UnwrapIfPromiseAsync Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
Contributor
Author
Added a new "Asynchronous Execution" section to the README in commit 4f86077. It covers |
lahma
approved these changes
Mar 1, 2026
lahma
marked this pull request as ready for review
March 1, 2026 07:04
Collaborator
|
@copilot tests seem to hang |
Copilot stopped work on behalf of
lahma due to an error
March 1, 2026 07:21
This was referenced Mar 2, 2026
This was referenced Jun 8, 2026
This was referenced Jul 6, 2026
This was referenced Jul 13, 2026
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.
UnwrapIfPromiseblocks the calling thread while waiting for aJsPromiseto settle, which causes thread pool exhaustion in async .NET environments.EvaluateAsync/InvokeAsynccover the common cases, but there's no async path when you already hold aJsValuethat may be a promise (e.g., fromCall(),GetValue(), etc.).Changes
Engine.Async.cs:UnwrapResultAsyncpromoted fromprivatetointernalto allow delegation from extension methods.JsValueExtensions.cs: NewUnwrapIfPromiseAsync(this JsValue, CancellationToken = default)extension — delegates topromise.Engine.UnwrapResultAsyncfor promises, short-circuits withTask.FromResultfor non-promise values.README.md: Added a new "Asynchronous Execution" section documentingEvaluateAsync/ExecuteAsync/InvokeAsyncandUnwrapIfPromiseAsyncwith code examples and guidance on when to use each.Usage
Respects
Options.Constraints.PromiseTimeoutand cancellation, matching the behaviour ofEvaluateAsync.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.