From c88381efe3c695b4dbcbdf837e6fe9ae5fc81dee Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 16 Mar 2018 11:17:38 -0400 Subject: [PATCH] Use `async` / `await` to improve readability --- js/modules/migrations/17/index.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/js/modules/migrations/17/index.js b/js/modules/migrations/17/index.js index 20631af15..feffbb058 100644 --- a/js/modules/migrations/17/index.js +++ b/js/modules/migrations/17/index.js @@ -17,29 +17,21 @@ const _initializeMessageSchemaVersion = messagesStore => const messagePutOperations = []; const cursorRequest = messagesStore.openCursor(); - cursorRequest.onsuccess = (event) => { + cursorRequest.onsuccess = async (event) => { const cursor = event.target.result; const hasMoreData = Boolean(cursor); if (!hasMoreData) { - // eslint-disable-next-line more/no-then - return Promise.all(messagePutOperations) - .then(() => resolve(messagePutOperations.length)); + await Promise.all(messagePutOperations); + return resolve(messagePutOperations.length); } const message = cursor.value; const messageWithSchemaVersion = Message.initializeSchemaVersion(message); - messagePutOperations.push(new Promise((resolvePut) => { - console.log( - 'Initialize schema version for message:', - messageWithSchemaVersion.id - ); - - resolvePut(putItem( - messagesStore, - messageWithSchemaVersion, - messageWithSchemaVersion.id - )); - })); + messagePutOperations.push(putItem( + messagesStore, + messageWithSchemaVersion, + messageWithSchemaVersion.id + )); return cursor.continue(); };