From e2ad4e6a8b0687424197ceefb158a2da696ccad2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 19 Jan 2018 11:37:07 -0800 Subject: [PATCH] Make StorageFolder.store async Signed-off-by: Nathan Sobo --- src/main-process/atom-application.js | 4 ++-- src/storage-folder.js | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 55c89b34f..d0db06daa 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -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') } } diff --git a/src/storage-folder.js b/src/storage-folder.js index b5d016fbc..24fdfd3de 100644 --- a/src/storage-folder.js +++ b/src/storage-folder.js @@ -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) {