Fixes #115: By introducing MQ workers
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -30,6 +30,9 @@ import {
|
||||
loadMarkdownExtensions,
|
||||
MDExt,
|
||||
} from "../common/markdown_parser/markdown_ext.ts";
|
||||
import { DexieMQ } from "../plugos/lib/mq.dexie.ts";
|
||||
import { MQHook } from "../plugos/hooks/mq.ts";
|
||||
import { mqSyscalls } from "../plugos/syscalls/mq.dexie.ts";
|
||||
|
||||
export class ClientSystem {
|
||||
system: System<SilverBulletHooks> = new System("client");
|
||||
@@ -44,6 +47,7 @@ export class ClientSystem {
|
||||
constructor(
|
||||
private editor: Client,
|
||||
private kvStore: DexieKVStore,
|
||||
private mq: DexieMQ,
|
||||
private dbPrefix: string,
|
||||
private eventHook: EventHook,
|
||||
) {
|
||||
@@ -66,6 +70,9 @@ export class ClientSystem {
|
||||
this.codeWidgetHook = new CodeWidgetHook();
|
||||
this.system.addHook(this.codeWidgetHook);
|
||||
|
||||
// MQ hook
|
||||
this.system.addHook(new MQHook(this.system, this.mq));
|
||||
|
||||
// Command hook
|
||||
this.commandHook = new CommandHook();
|
||||
this.commandHook.on({
|
||||
@@ -115,6 +122,7 @@ export class ClientSystem {
|
||||
markdownSyscalls(buildMarkdown(this.mdExtensions)),
|
||||
assetSyscalls(this.system),
|
||||
yamlSyscalls(),
|
||||
mqSyscalls(this.mq),
|
||||
storeCalls,
|
||||
this.indexSyscalls,
|
||||
debugSyscalls(),
|
||||
|
||||
Reference in New Issue
Block a user