Support Promise response in trySave

In Atom 1.19, TextBuffer.save returns a Promise. This commit adds
support to catch this and resolve our internal callbacks when promise
resolves.
This commit is contained in:
Edvin Hultberg 2017-07-27 15:58:50 +02:00
parent 4747bcf5e8
commit b5cb054b39

View file

@ -17,8 +17,13 @@ trySave = (func) ->
deferred = defer() deferred = defer()
try try
func() response = func()
deferred.resolve()
if response instanceof Promise
response.then ->
deferred.resolve()
else
deferred.resolve()
catch error catch error
if error.message.endsWith('is a directory') if error.message.endsWith('is a directory')
atom.notifications.addWarning("Unable to save file: #{error.message}") atom.notifications.addWarning("Unable to save file: #{error.message}")
@ -252,7 +257,7 @@ class Ex
@write(args) @write(args)
wq: (args) => wq: (args) =>
@write(args).then => @quit() @write(args).then(=> @quit())
wa: => wa: =>
@wall() @wall()