Skip to content

Commit

Permalink
Avoid race-condition by using await
Browse files Browse the repository at this point in the history
Otherwise the wrong driver might be used because the right driver hasn't
been succesfully configured yet.
  • Loading branch information
jcbrand committed Jul 31, 2023
1 parent 7011d38 commit 035453b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.0 (Unreleased)

- Fix a race condition when setting a localForage driver

## 0.0.8 (2023-02-14)

- Use the released version of `@converse/localforage-getitems`
Expand Down
4 changes: 2 additions & 2 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class Storage {

async initStore (type, batchedWrites) {
if (type === 'session') {
localForage.setDriver(sessionStorageWrapper._driver);
await localForage.setDriver(sessionStorageWrapper._driver);
} else if (type === 'local') {
await localForage.config({'driver': localForage.LOCALSTORAGE});
} else if (type === 'in_memory') {
localForage.config({'driver': IN_MEMORY});
await localForage.config({'driver': IN_MEMORY});
} else if (type !== 'indexed') {
throw new Error("Skeletor.storage: No storage type was specified");
}
Expand Down

0 comments on commit 035453b

Please sign in to comment.