Use async
/ await
to improve readability
This commit is contained in:
parent
2642844c27
commit
c88381efe3
1 changed files with 8 additions and 16 deletions
|
@ -17,29 +17,21 @@ const _initializeMessageSchemaVersion = messagesStore =>
|
||||||
const messagePutOperations = [];
|
const messagePutOperations = [];
|
||||||
|
|
||||||
const cursorRequest = messagesStore.openCursor();
|
const cursorRequest = messagesStore.openCursor();
|
||||||
cursorRequest.onsuccess = (event) => {
|
cursorRequest.onsuccess = async (event) => {
|
||||||
const cursor = event.target.result;
|
const cursor = event.target.result;
|
||||||
const hasMoreData = Boolean(cursor);
|
const hasMoreData = Boolean(cursor);
|
||||||
if (!hasMoreData) {
|
if (!hasMoreData) {
|
||||||
// eslint-disable-next-line more/no-then
|
await Promise.all(messagePutOperations);
|
||||||
return Promise.all(messagePutOperations)
|
return resolve(messagePutOperations.length);
|
||||||
.then(() => resolve(messagePutOperations.length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = cursor.value;
|
const message = cursor.value;
|
||||||
const messageWithSchemaVersion = Message.initializeSchemaVersion(message);
|
const messageWithSchemaVersion = Message.initializeSchemaVersion(message);
|
||||||
messagePutOperations.push(new Promise((resolvePut) => {
|
messagePutOperations.push(putItem(
|
||||||
console.log(
|
messagesStore,
|
||||||
'Initialize schema version for message:',
|
messageWithSchemaVersion,
|
||||||
messageWithSchemaVersion.id
|
messageWithSchemaVersion.id
|
||||||
);
|
));
|
||||||
|
|
||||||
resolvePut(putItem(
|
|
||||||
messagesStore,
|
|
||||||
messageWithSchemaVersion,
|
|
||||||
messageWithSchemaVersion.id
|
|
||||||
));
|
|
||||||
}));
|
|
||||||
|
|
||||||
return cursor.continue();
|
return cursor.continue();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue