Make StorageFolder.store async

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Max Brunsfeld 2018-01-19 11:37:07 -08:00 committed by Nathan Sobo
parent 7c8f73b2d8
commit e2ad4e6a8b
2 changed files with 9 additions and 6 deletions

View File

@ -909,7 +909,7 @@ class AtomApplication extends EventEmitter {
}
}
saveState (allowEmpty = false) {
async saveState (allowEmpty = false) {
if (this.quitting) return
const states = []
@ -919,7 +919,7 @@ class AtomApplication extends EventEmitter {
states.reverse()
if (states.length > 0 || allowEmpty) {
this.storageFolder.storeSync('application.json', states)
await this.storageFolder.store('application.json', states)
this.emit('application:did-save-state')
}
}

View File

@ -19,10 +19,13 @@ class StorageFolder {
})
}
storeSync (name, object) {
if (!this.path) return
fs.writeFileSync(this.pathForKey(name), JSON.stringify(object), 'utf8')
store (name, object) {
return new Promise((resolve, reject) => {
if (!this.path) return resolve()
fs.writeFile(this.pathForKey(name), JSON.stringify(object), 'utf8', error =>
error ? reject(error) : resolve()
)
})
}
load (name) {