Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3624 from matrix-org/t3chguy/remove_bluebird_2
Browse files Browse the repository at this point in the history
Attempt number two at ripping out Bluebird from rageshake.js
  • Loading branch information
t3chguy committed Nov 18, 2019
2 parents 759b497 + 2fe764a commit 050761d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/rageshake/rageshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class IndexedDBLogStore {
this.id = "instance-" + Math.random() + Date.now();
this.index = 0;
this.db = null;

// these promises are cleared as soon as fulfilled
this.flushPromise = null;
// set if flush() is called whilst one is ongoing
this.flushAgainPromise = null;
Expand Down Expand Up @@ -208,25 +210,24 @@ class IndexedDBLogStore {
*/
flush() {
// check if a flush() operation is ongoing
if (this.flushPromise && this.flushPromise.isPending()) {
if (this.flushAgainPromise && this.flushAgainPromise.isPending()) {
// this is the 3rd+ time we've called flush() : return the same
// promise.
if (this.flushPromise) {
if (this.flushAgainPromise) {
// this is the 3rd+ time we've called flush() : return the same promise.
return this.flushAgainPromise;
}
// queue up a flush to occur immediately after the pending one
// completes.
// queue up a flush to occur immediately after the pending one completes.
this.flushAgainPromise = this.flushPromise.then(() => {
return this.flush();
}).then(() => {
this.flushAgainPromise = null;
});
return this.flushAgainPromise;
}
// there is no flush promise or there was but it has finished, so do
// a brand new one, destroying the chain which may have been built up.
this.flushPromise = new Promise((resolve, reject) => {
if (!this.db) {
// not connected yet or user rejected access for us to r/w to
// the db.
// not connected yet or user rejected access for us to r/w to the db.
reject(new Error("No connected database"));
return;
}
Expand All @@ -251,6 +252,8 @@ class IndexedDBLogStore {
objStore.add(this._generateLogEntry(lines));
const lastModStore = txn.objectStore("logslastmod");
lastModStore.put(this._generateLastModifiedTime());
}).then(() => {
this.flushPromise = null;
});
return this.flushPromise;
}
Expand Down

0 comments on commit 050761d

Please sign in to comment.