Use Promise constructor instead of Promise.defer. Fix #110.
This commit is contained in:
parent
5773c8f47b
commit
3a43853292
1 changed files with 39 additions and 43 deletions
|
|
@ -4,11 +4,10 @@ fs = require 'fs-plus'
|
|||
VimOption = require './vim-option'
|
||||
|
||||
trySave = (func) ->
|
||||
deferred = Promise.defer()
|
||||
|
||||
new Promise (resolve) ->
|
||||
try
|
||||
func()
|
||||
deferred.resolve()
|
||||
resolve()
|
||||
catch error
|
||||
if error.message.endsWith('is a directory')
|
||||
atom.notifications.addWarning("Unable to save file: #{error.message}")
|
||||
|
|
@ -30,7 +29,6 @@ trySave = (func) ->
|
|||
else
|
||||
throw error
|
||||
|
||||
deferred.promise
|
||||
|
||||
saveAs = (filePath) ->
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
|
|
@ -150,7 +148,7 @@ class Ex
|
|||
if filePath.indexOf(' ') isnt -1
|
||||
throw new CommandError('Only one file name allowed')
|
||||
|
||||
deferred = Promise.defer()
|
||||
new Promise (resolve) ->
|
||||
|
||||
editor = atom.workspace.getActiveTextEditor()
|
||||
saved = false
|
||||
|
|
@ -158,7 +156,7 @@ class Ex
|
|||
fullPath = getFullPath(filePath)
|
||||
if editor.getPath()? and (not fullPath? or editor.getPath() == fullPath)
|
||||
# Use editor.save when no path is given or the path to the file is given
|
||||
trySave(-> editor.save()).then(deferred.resolve)
|
||||
trySave(-> editor.save()).then(resolve)
|
||||
saved = true
|
||||
else if not fullPath?
|
||||
fullPath = atom.showSaveDialogSync()
|
||||
|
|
@ -166,9 +164,7 @@ class Ex
|
|||
if not saved and fullPath?
|
||||
if not force and fs.existsSync(fullPath)
|
||||
throw new CommandError("File exists (add ! to override)")
|
||||
trySave(-> saveAs(fullPath)).then(deferred.resolve)
|
||||
|
||||
deferred.promise
|
||||
trySave(-> saveAs(fullPath)).then(resolve)
|
||||
|
||||
w: (args...) =>
|
||||
@write(args...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue