Instead of passing around the deferred, I think the code should probably writeAtomic.then(deferred.resolve)