Changes required due to TextBuffer.save becoming async in Atom 1.19
Closed this issue · 3 comments
Hi! Thanks for maintaining the run-in-terminal package!
In Atom v1.19, we will release a major change to Atom's core text buffer data structure. As part of this change, we have made TextBuffer.save
asynchronous; rather than blocking until the save is complete, it now immediately returns a Promise
that resolves when the save is complete. Because of this, a few other Atom APIs that use save
have similarly become async:
Pane.close
TextBuffer.save
TextEditor.save
Pane.saveItem
Pane.saveItemAs
Pane.saveActiveItem
Pane.saveActiveItemAs
Pane.saveItems
Workspace.saveActivePaneItem
Workspace.saveActivePaneItemAs
Effects on this package
We think this package could be impacted by this upgrade because it calls the changed methods in the following places:
TextEditor.save
We found these calls using a regex search, so this list might be incomplete, and it might contain some false positives.
What to do about the change
It should be pretty easy to adjust your package code and/or tests to work with the new async behavior, and to simultaneously keep it working with older versions of Atom. Here are some examples of pull requests we opened on our bundled packages to cope with the change:
- atom/autocomplete-plus#852
- atom/whitespace#155
- atom/symbols-view#222
- atom/status-bar#193
- atom/tabs#448
Please let me know if you have any questions. I would be happy to help!
Don't get how to change my code. AFAIR I can't use await
(coffescript does not support it). How should I write this just to wait until editor will be saved?
I think you should make your save_file_in_editor
function return a Promise
and wait for that promise to resolve before you execute the child process. Something like this:
save_file_in_editor = (file_path) ->
if read_option("save_before_launch")
for editor in atom.workspace.getTextEditors()
if file_path == editor.getPath() and editor.isModified()
# Wrap in `Promise.all` for compatibility with older versions of Atom,
# in which `save` does not return a Promise.
return Promise.resolve(editor.save())
# Fall back to a promise that resolves immediately
return Promise.resolve()
start_terminal = (start_path, args) =>
# ...
# Wait until the promise resolves before continuing on.
save_file_in_editor(file_path).then =>
# ...
@maxbrunsfeld thanks for help! Hope to see await
in coffeescript, since promises are pretty ugly.