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) =>
@_atomicPromise ?= Promise.resolve()
@_atomicPromise = @_atomicPromise.finally =>
@_atomicPromise = @_atomicPromise.then =>
@_atomically(fn)
return @_atomicPromise
_atomically: (fn) ->
@_query("BEGIN EXCLUSIVE TRANSACTION")
.then => fn()
.then => @_query("COMMIT")
.then => Promise.resolve()
.then =>
fn()
.then (val) =>
@_query("COMMIT").then =>
Promise.resolve(val)
########################################################################
########################### PRIVATE METHODS ############################