Fixes #115: By introducing MQ workers

This commit is contained in:
Zef Hemel
2023-08-10 18:32:41 +02:00
parent c6fce524e6
commit 97a84e8538
16 changed files with 544 additions and 7 deletions
+10
View File
@@ -33,6 +33,7 @@ import { ClientSystem } from "./client_system.ts";
import { createEditorState } from "./editor_state.ts";
import { OpenPages } from "./open_pages.ts";
import { MainUI } from "./editor_ui.tsx";
import { DexieMQ } from "../plugos/lib/mq.dexie.ts";
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
const autoSaveInterval = 1000;
@@ -75,6 +76,7 @@ export class Client {
syncService: SyncService;
settings!: BuiltinSettings;
kvStore: DexieKVStore;
mq: DexieMQ;
// Event bus used to communicate between components
eventHook: EventHook;
@@ -94,6 +96,13 @@ export class Client {
globalThis.indexedDB,
);
this.mq = new DexieMQ(`${this.dbPrefix}_mq`, indexedDB, IDBKeyRange);
setInterval(() => {
// Timeout after 5s
this.mq.requeueTimeouts(5000, 3).catch(console.error);
}, 20000); // Look to requeue every 20s
// Event hook
this.eventHook = new EventHook();
@@ -101,6 +110,7 @@ export class Client {
this.system = new ClientSystem(
this,
this.kvStore,
this.mq,
this.dbPrefix,
this.eventHook,
);