-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include output from interactive cells in Foyle requests #1756
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d279e74
Include output from interactive cells in Foyle requests
jlewi 67fd224
Merge remote-tracking branch 'upstream/main' into jlewi/outputs
jlewi 2e2dcd6
Update to use await.
jlewi 328740d
Add a comment.
jlewi 67df280
Use await.
jlewi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sourishkrout Is this the right way to call an async function from a non async function?
Since the return type is null we don't need to await the async function.
However, I think in the past you mentioned that if you invoke an async function but don't do anything with its return value it might not get scheduled.
Does using "then(()=> {})" solve this problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not solve the problem. At JS runtime, there isn't such a thing as an "async function". What makes it async is returning a
Promise<>
type. Async/await uses a generator under the hood to pause execution to unravel promises; however, semantically, there's no difference to.then(...)
. It just makes you write async code that looks much more like sync code for readability.That being said, if a promise type ("a future") is not being then'd or awaited upstream, you wind up with the same exact problem no matter how the promise is "returned."
The only reason this likely appears to work is that promises start running immediately (as opposed to when you await/then them), and VS Code is a long-running process, so the scopes live long enough to allow the promises to complete. I'm making assumptions here because I haven't thoroughly inspected the upstream code.
As a Golang programmer, this is the same as running three
go func()
inside a function but not using a WaitGroup to synchronize them. Similarly, this might work if the "main thread" runs long enough for all three to complete and no downstream processing requires their completion. Otherwise, all concurrent functions get killed when the main thread dies.In other words, my suggestion to use
async
was only intended to be cosmetic. If there is a problem with async execution, boththen
andawait
will be prone to it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems fine to me. Concretely, it seems fine to treat it as a fire and forget and assume
or
Here's the problem I'm trying to solve. handleEvent is an async function being called from a non async function handleOnDidChangeNotebookCell. handleOnDidChangeNotebookCell is the listener for events
vscode-runme/src/extension/ai/manager.ts
Line 60 in 165da75
I originally thought I couldn't declare handleEvent as async and include an await function because I thought the listener couldn't be an async function. However, it looks like if I declare handleOnDidChangeNotebookCell to be async it still works fine; so I could update it to be async and then include an await function.
However, my suposition is that if the listener (handleOnDidChangeNotebookCell) is async its returning a promise that is not being awaited on. So we still wind up with a Promise that we aren't awaiting its just happening in a different part of the code.
Fundamentally, I think this is alright. The listener (handleOnDidChangeNotebookCell) is firing off a request to generate a completion and the response is handled asynchronously. If vscode exits before that async function can get scheduled and finish processing than we are dropping the completion generation logic on the floor rather than doing some graceful handling/shutdown. But dropping it on the floor seems fine; I'm not sure what graceful handling would actually look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I changed handleOnDidChangeNotebookCell and added some awaits. I made this change because I agree with your earlier comment that using await is cleaner.
@sourishkrout so I think this is good to go but let me know if you think otherwise.