Change Pane::saveItems to return a promise… - #1596
Open
savetheclocktower wants to merge 2 commits into
Open
Conversation
…that resolves when all items have been saved.
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.
…that resolves when all items have been saved.
I was doing some tending of the
typesrepo and looking over our documentation forPane. I realized that nearly all of our pane methods related to saving items returned promises —Pane::saveItem,Pane::saveActiveItem,Pane::saveItemAs,Pane::saveActiveItemAs. This reflects the fact that saving can go async for a couple of reasons:savemethod on a pane item anticipates that saving itself might be an async process. (For instance: anything can attach an asynconWillSavecallback to aTextBuffer; whenTextBuffer::saveis called, it does not resolve until all those async callbacks resolve.)So it's weird to me that
Pane::saveItemsdoesn't go async. When called, it finds all the items that need saving in a given pane (the ones for whomisModifiedis defined and returnstrue) and then callsPane::saveItemon each in turn. But then it just returns!I don't have a specific use case in mind, but it took me all of 15 minutes to enhance
Pane::saveItemsso that it goes async and doesn't resolve until all modified items in the pane have finished saving. This should have no effect on existing usages ofsaveItems, since that function did not have any return value previously.Testing
I added a new spec in the
Panesuite; if CI likes it, that should be good enough to prove that this works.The spec was added in isolation in the first commit of this PR; so if you like, you can check out that commit and run the new spec in order to verify that it fails. Then you can check out the second commit to verify that the new spec passes.