fix(db): Atomically was not resolving with a value, fixes mail notifications

This commit is contained in:
Ben Gotow 2015-09-22 17:32:57 -07:00
parent a35416ae94
commit 42f65798d6

View file

@ -462,15 +462,17 @@ class DatabaseStore extends NylasStore
atomically: (fn) => atomically: (fn) =>
@_atomicPromise ?= Promise.resolve() @_atomicPromise ?= Promise.resolve()
@_atomicPromise = @_atomicPromise.finally => @_atomicPromise = @_atomicPromise.then =>
@_atomically(fn) @_atomically(fn)
return @_atomicPromise return @_atomicPromise
_atomically: (fn) -> _atomically: (fn) ->
@_query("BEGIN EXCLUSIVE TRANSACTION") @_query("BEGIN EXCLUSIVE TRANSACTION")
.then => fn() .then =>
.then => @_query("COMMIT") fn()
.then => Promise.resolve() .then (val) =>
@_query("COMMIT").then =>
Promise.resolve(val)
######################################################################## ########################################################################
########################### PRIVATE METHODS ############################ ########################### PRIVATE METHODS ############################