Skip to content

Instantly share code, notes, and snippets.

@pke
Created November 27, 2014 22:43
Show Gist options
  • Save pke/7d95d7b13c9f37568278 to your computer and use it in GitHub Desktop.
Save pke/7d95d7b13c9f37568278 to your computer and use it in GitHub Desktop.
saveAsync
savesPending: 0
saveAsync: () ->
#assert(!@finished, "Inspection already finished!")
logger.debug("Save requested (_cachedFile=#{@_cachedFile})")
if @saving
@savesPending += 1
logger.debug("saveAsync: already saving, #{@savesPending} pending now")
return @saving
@saving = getCachedFile(@serialNumber)
.then (file) =>
logger.debug("saveAsync: saving...")
@node.ownerDocument.saveToFileAsync(file)
.then null, (error) =>
logger.error("saveAsync: failed with inspection #{@serialNumber} but #{@savesPending} saves pending - good luck!", error)
.then =>
logger.debug("saveAsync: saved and #{@savesPending} pending")
@saving = null
if @savesPending
@savesPending = 0
@saving = @saveAsync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment