Chain promises better

This commit is contained in:
probablycorey
2013-10-07 11:46:03 -07:00
parent f9250e3dd1
commit 13232de4b9
2 changed files with 8 additions and 9 deletions

View File

@@ -192,15 +192,14 @@ class Project
#
# Returns a promise that resolves to an {EditSession}.
openAsync: (filePath, options={}) ->
for opener in @openers
return Q(resource) if resource = opener(filePath, options)
resource = null
_.find @openers, (opener) -> resource = opener(filePath, options)
deferred = Q.defer()
@bufferForPathAsync(filePath).then (buffer) =>
editSession = @buildEditSessionForBuffer(buffer, options)
deferred.resolve(editSession)
deferred.promise
if resource
Q(resource)
else
@bufferForPathAsync(filePath).then (buffer) =>
editSession = @buildEditSessionForBuffer(buffer, options)
# Private: DEPRECATED
open: (filePath, options={}) ->

View File

@@ -75,7 +75,7 @@ class TextBuffer
@updateCachedDiskContentsAsync().then =>
@reload() if @loadFromDisk and @isModified()
@text.clearUndoStack()
Q(this)
this
### Internal ###