Commit 06753eae by Sixong.Zhu

control setup

parent eb042a64
Showing with 20 additions and 0 deletions
......@@ -13,9 +13,28 @@ class ChatCacheDatabaseController {
private readonly chatListKey = "chat-list";
private readonly chatMessageKey = "chat-message";
private setuping = false;
private waitSetupCompleted() {
return new Promise<void>(resolve => {
const checker = () => {
if (!this.setuping) {
resolve();
} else {
setTimeout(() => checker(), 200);
}
};
checker();
});
}
public setup(uid: string) {
if (this.setuping) {
return this.waitSetupCompleted();
}
return new Promise<void>((resolve) => {
if (uid && indexedDB) {
this.setuping = true;
const r = indexedDB.open(
"u-" + (this.uid = uid),
this.listVersion
......@@ -33,6 +52,7 @@ class ChatCacheDatabaseController {
console.error(e);
}
}
this.setuping = false;
resolve();
};
r.onsuccess = function(e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment