From 526f0d1ce36138a5b688005676e38dae3ff1ac43 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Wed, 28 Nov 2018 17:02:01 +0000 Subject: [PATCH 1/3] Use cursor ranges to be more performant when iterating through IDB Fixes #36 --- .../WatchableMessageStore.d.ts | 1 + .../WatchableMessageStore.js | 37 +++++++++---------- .../WatchableMessageStore.js.map | 2 +- .../WatchableMessageStore.ts | 11 +++++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/watchable-message-store/WatchableMessageStore.d.ts b/lib/watchable-message-store/WatchableMessageStore.d.ts index 8081b9d..2e5fd92 100644 --- a/lib/watchable-message-store/WatchableMessageStore.d.ts +++ b/lib/watchable-message-store/WatchableMessageStore.d.ts @@ -46,6 +46,7 @@ export declare class WatchableMessageStore { private bcc?; private dbName; private objStoreName; + private _lastCursorId; constructor(name: string); private init; /** diff --git a/lib/watchable-message-store/WatchableMessageStore.js b/lib/watchable-message-store/WatchableMessageStore.js index 665e660..d88a6cb 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js +++ b/lib/watchable-message-store/WatchableMessageStore.js @@ -15,8 +15,8 @@ // 1 frame. E.g. this value needs to be higher than 16ms. Otherwise, the // IDB connection will starve and run into an endless loop. const POLLING_INTERVAL = 50; -const DB_PREFIX = "ACTOR-DATABASE"; -const OBJECT_STORE_NAME = "LIST"; +const DB_PREFIX = 'ACTOR-DATABASE'; +const OBJECT_STORE_NAME = 'LIST'; /** * A messageStore that can read and write to a specific objectStore in an * IndexedDB database. This class is used to implement message passing for @@ -32,9 +32,10 @@ export class WatchableMessageStore { constructor(name) { this.name = name; this.objStoreName = OBJECT_STORE_NAME; + this._lastCursorId = 0; this.dbName = `${DB_PREFIX}.${name}`; this.database = this.init(); - if ("BroadcastChannel" in self) { + if ('BroadcastChannel' in self) { this.bcc = new BroadcastChannel(name); } } @@ -49,9 +50,7 @@ export class WatchableMessageStore { }; connection.onupgradeneeded = () => { if (!connection.result.objectStoreNames.contains(this.objStoreName)) { - connection.result.createObjectStore(this.objStoreName, { - autoIncrement: true - }); + connection.result.createObjectStore(this.objStoreName, { autoIncrement: true }); } }; }); @@ -66,10 +65,9 @@ export class WatchableMessageStore { * processed the message. */ async popMessages(recipient, { keepMessage = false } = {}) { - const transaction = (await this.database).transaction(this.objStoreName, "readwrite"); - const cursorRequest = transaction - .objectStore(this.objStoreName) - .openCursor(); + const transaction = (await this.database).transaction(this.objStoreName, 'readwrite'); + const cursorRequest = transaction.objectStore(this.objStoreName) + .openCursor(IDBKeyRange.lowerBound(this._lastCursorId, true)); return new Promise((resolve, reject) => { const messages = []; cursorRequest.onerror = () => { @@ -79,13 +77,14 @@ export class WatchableMessageStore { const cursor = cursorRequest.result; if (cursor) { const value = cursor.value; - if (value.recipient === recipient || recipient === "*") { + if (value.recipient === recipient || recipient === '*') { messages.push(value); if (!keepMessage) { cursor.delete(); } } cursor.continue(); + this._lastCursorId = cursor.key; } else { resolve(messages); @@ -99,19 +98,17 @@ export class WatchableMessageStore { * @param message The message to store with a recipient and a detail. */ async pushMessage(message) { - if (message.recipient === "*") { - throw new Error("Can’t send a message to reserved name '*'"); + if (message.recipient === '*') { + throw new Error('Can’t send a message to reserved name \'*\''); } - const transaction = (await this.database).transaction(this.objStoreName, "readwrite"); + const transaction = (await this.database).transaction(this.objStoreName, 'readwrite'); return new Promise((resolve, reject) => { transaction.onerror = () => { reject(transaction.error); }; transaction.oncomplete = () => { if (this.bcc) { - this.bcc.postMessage({ - recipient: message.recipient - }); + this.bcc.postMessage({ recipient: message.recipient }); } resolve(); }; @@ -130,9 +127,9 @@ export class WatchableMessageStore { callback(messages); } }; - channel.addEventListener("message", channelCallback); + channel.addEventListener('message', channelCallback); // Check for already stored messages immediately - channelCallback(new MessageEvent("message", { data: { recipient } })); + channelCallback(new MessageEvent('message', { data: { recipient } })); return () => { channel.close(); }; @@ -163,7 +160,7 @@ export class WatchableMessageStore { */ subscribe(recipient, callback) { let unsubscribe = null; - if ("BroadcastChannel" in self) { + if ('BroadcastChannel' in self) { unsubscribe = this.subscribeWithBroadcastChannel(recipient, callback); } else { diff --git a/lib/watchable-message-store/WatchableMessageStore.js.map b/lib/watchable-message-store/WatchableMessageStore.js.map index 26b533f..583d551 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js.map +++ b/lib/watchable-message-store/WatchableMessageStore.js.map @@ -1 +1 @@ -{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAqBjC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAMhC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFxB,iBAAY,GAAG,iBAAiB,CAAC;QAGvC,IAAI,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACvC;IACH,CAAC;IAEO,IAAI;QACV,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE/C,UAAU,CAAC,OAAO,GAAG,GAAG,EAAE;gBACxB,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC;YAEF,UAAU,CAAC,SAAS,GAAG,GAAG,EAAE;gBAC1B,OAAO,CAAC,UAAU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A6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SACvE;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC9D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file +{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAqBjC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAOhC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAHxB,iBAAY,GAAG,iBAAiB,CAAC;QACjC,kBAAa,GAAG,CAAC,CAAC;QAGxB,IAAI,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACvC;IACH,CAAC;IAEO,IAAI;QACV,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE/C,UAAU,CAAC,OAAO,GAAG,GAAG,EAAE;gBACxB,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC;YAEF,UAAU,CAAC,SAAS,GAAG,GAAG,EAAE;gBAC1B,OAAO,CAAC,UAAU,CAAC,M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AAI,WAAW,GAAG,IAAI,CAAC;QAEvB,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,WAAW,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SACvE;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC9D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file diff --git a/src/watchable-message-store/WatchableMessageStore.ts b/src/watchable-message-store/WatchableMessageStore.ts index 296baa4..5e9491d 100644 --- a/src/watchable-message-store/WatchableMessageStore.ts +++ b/src/watchable-message-store/WatchableMessageStore.ts @@ -60,6 +60,7 @@ export class WatchableMessageStore { private bcc?: BroadcastChannel; private dbName: string; private objStoreName = OBJECT_STORE_NAME; + private _lastCursorId = 0; constructor(private name: string) { this.dbName = `${DB_PREFIX}.${name}`; @@ -103,7 +104,11 @@ export class WatchableMessageStore { */ async popMessages( recipient: string, - { keepMessage = false }: { keepMessage?: boolean } = {} + { + keepMessage = false + }: { + keepMessage?: boolean; + } = {} ) { const transaction = (await this.database).transaction( this.objStoreName, @@ -112,7 +117,7 @@ export class WatchableMessageStore { const cursorRequest = transaction .objectStore(this.objStoreName) - .openCursor(); + .openCursor(IDBKeyRange.lowerBound(this._lastCursorId, true)); return new Promise((resolve, reject) => { const messages: StoredMessage[] = []; @@ -136,6 +141,8 @@ export class WatchableMessageStore { } cursor.continue(); + + this._lastCursorId = cursor.key as number; } else { resolve(messages); } From ae7916b26b637260205c550e68680265c354ded3 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 29 Nov 2018 14:04:58 +0000 Subject: [PATCH 2/3] Fix resetting cursor on hookup and add test --- lib/actor/Actor.js | 21 +++--- lib/actor/Actor.js.map | 2 +- lib/actor/Actor_test.d.ts | 6 +- lib/actor/Actor_test.js | 71 +++++++++++++------ lib/actor/Actor_test.js.map | 2 +- .../WatchableMessageStore.d.ts | 2 +- .../WatchableMessageStore.js | 39 +++++----- .../WatchableMessageStore.js.map | 2 +- src/actor/Actor.ts | 19 ++--- src/actor/Actor_test.ts | 41 ++++++++++- .../WatchableMessageStore.ts | 6 +- 11 files changed, 140 insertions(+), 71 deletions(-) diff --git a/lib/actor/Actor.js b/lib/actor/Actor.js index 9292c67..d6955a2 100644 --- a/lib/actor/Actor.js +++ b/lib/actor/Actor.js @@ -11,7 +11,7 @@ * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -import { WatchableMessageStore } from "../watchable-message-store/WatchableMessageStore.js"; +import { WatchableMessageStore } from '../watchable-message-store/WatchableMessageStore.js'; /** * A mixin function to define an Actor type. It creates a class with a stub * for the {@link Actor#onMessage} callback, which must be overwritten. @@ -38,7 +38,8 @@ import { WatchableMessageStore } from "../watchable-message-store/WatchableMessa * * onMessage(message: MessageType) { * this.count!++; - * console.log(`Actor ${this.actorName} received message number ${this.count}: ${message}`); + * console.log(`Actor ${this.actorName} received message number + * ${this.count}: ${message}`); * } * } * @@ -54,7 +55,8 @@ export function actorMixin(superClass) { constructor() { super(...arguments); /** - * Do not use, it is an internal implementation detail used in {@link hookup}. + * Do not use, it is an internal implementation detail used in {@link + * hookup}. */ this.initPromise = Promise.resolve().then(() => this.init()); } @@ -133,7 +135,8 @@ export function actorMixin(superClass) { * * onMessage(message: MessageType) { * this.count!++; - * console.log(`Actor ${this.actorName} received message number ${this.count}: ${message}`); + * console.log(`Actor ${this.actorName} received message number + * ${this.count}: ${message}`); * } * } * @@ -147,7 +150,7 @@ export function actorMixin(superClass) { export class Actor extends actorMixin(Object) { async init() { } } -const messageStore = new WatchableMessageStore("ACTOR-MESSAGES"); +const messageStore = new WatchableMessageStore('ACTOR-MESSAGES'); /** * Hookup an {@link Actor} with a name into system. In this case, the actor * will initialize and respond to any messages designated for `actorName`. @@ -178,6 +181,7 @@ export async function hookup(actorName, actor, { purgeExistingMessages = false } actor.actorName = actorName; // @ts-ignore await actor.initPromise; + messageStore.lastCursorId = 0; if (purgeExistingMessages) { await messageStore.popMessages(actorName); } @@ -240,10 +244,7 @@ export async function hookup(actorName, actor, { purgeExistingMessages = false } export function lookup(actorName) { return { async send(message) { - await messageStore.pushMessage({ - recipient: actorName, - detail: message - }); + await messageStore.pushMessage({ recipient: actorName, detail: message }); } }; } @@ -271,6 +272,6 @@ export function lookup(actorName) { * hookup("database", new DatabaseActor()); */ export async function initializeQueues() { - await messageStore.popMessages("*"); + await messageStore.popMessages('*'); } //# sourceMappingURL=Actor.js.map \ No newline at end of file diff --git a/lib/actor/Actor.js.map b/lib/actor/Actor.js.map index a6ce8b7..243f678 100644 --- a/lib/actor/Actor.js.map +++ b/lib/actor/Actor.js.map @@ -1 +1 @@ -{"version":3,"file":"Actor.js","sourceRoot":"","sources":["../../src/actor/Actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAwC5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,UAAU,CACxB,UAAa;IAEb,OAAO,KAAM,SAAQ,UAAU;QAAxB;;YACL;;eAEG;YACM,gBAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAyDnE,CAAC;QAlDC;;;;;;;;;WASG;QACH,KAAK,CAAC,IAAI,KAAmB,CAAC;QAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAkCG;QACH,SAAS,CAAC,CAAI;YACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAgB,KAAS,SAAQ,UAAU,CAAC,MAAM,CA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AAY,CAAC,YAAY,GAAG,CAAC,CAAC;IAE9B,IAAI,qBAAqB,EAAE;QACzB,MAAM,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;KAC3C;IAED,MAAM,QAAQ,GAAG,YAAY,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAC5D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,IAAI;gBACF,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,MAAqC,CAAC,CAAC;aAChE;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClB;SACF;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,IAAI,EAAE;QAChB,QAAQ,EAAE,CAAC;QACX,MAAM,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,MAAM,CAClB,SAAoB;IACtB,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAoC;YAC7C,MAAM,YAAY,CAAC,WAAW,CAAC,EAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;QAC1E,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,MAAM,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/lib/actor/Actor_test.d.ts b/lib/actor/Actor_test.d.ts index fb7df17..f39dbcc 100644 --- a/lib/actor/Actor_test.d.ts +++ b/lib/actor/Actor_test.d.ts @@ -13,9 +13,9 @@ */ declare global { interface ActorMessageType { - ignoring: "dummy"; - ignoring1: "foo"; - late: "dummy"; + ignoring: 'dummy'; + ignoring1: 'foo'; + late: 'dummy'; } } export {}; diff --git a/lib/actor/Actor_test.js b/lib/actor/Actor_test.js index f972ced..197e808 100644 --- a/lib/actor/Actor_test.js +++ b/lib/actor/Actor_test.js @@ -11,12 +11,12 @@ * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -import { Actor, hookup, lookup, initializeQueues } from "./Actor.js"; +import { Actor, hookup, initializeQueues, lookup } from './Actor.js'; const { suite, test, teardown, setup } = window.Mocha; const { assert } = window; -suite("Actor", () => { +suite('Actor', () => { let hookdown; - setup(async function () { + setup(async () => { await initializeQueues(); }); teardown(async () => { @@ -24,54 +24,79 @@ suite("Actor", () => { await hookdown(); } }); - test("can hookup an actor", async () => { + test('can hookup an actor', async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - hookdown = await hookup("ignoring1", new IgnoringActor()); - await lookup("ignoring1").send("foo"); + hookdown = await hookup('ignoring1', new IgnoringActor()); + await lookup('ignoring1').send('foo'); }); }); - test("can lookup an actor and send a message", async () => { + test('can lookup an actor and send a message', async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - hookdown = await hookup("ignoring", new IgnoringActor()); - await lookup("ignoring").send("dummy"); + hookdown = await hookup('ignoring', new IgnoringActor()); + await lookup('ignoring').send('dummy'); }); }); - test("can call lookup before hookup", async () => { + test('can call lookup before hookup', async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - await lookup("ignoring").send("dummy"); + await lookup('ignoring').send('dummy'); setTimeout(async () => { - hookdown = await hookup("ignoring", new IgnoringActor()); + hookdown = await hookup('ignoring', new IgnoringActor()); }, 100); }); }); - test("can retrieve own actor name", async () => { + test('re-traverses messages after hookup', async () => { + await new Promise(async (resolve) => { + let ignoringHookdown; + class LateActor extends Actor { + onMessage() { + console.log('late called'); + resolve(); + } + } + class IgnoringActor extends Actor { + onMessage() { + setTimeout(async () => { + const lateHookdown = await hookup('late', new LateActor()); + hookdown = async () => { + await ignoringHookdown(); + await lateHookdown(); + }; + }, 100); + } + } + await lookup('late').send('dummy'); + await lookup('ignoring').send('dummy'); + ignoringHookdown = await hookup('ignoring', new IgnoringActor()); + }); + }); + test('can retrieve own actor name', async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { - assert.equal(this.actorName, "ignoring"); + assert.equal(this.actorName, 'ignoring'); resolve(); } } - hookdown = await hookup("ignoring", new IgnoringActor()); - await lookup("ignoring").send("dummy"); + hookdown = await hookup('ignoring', new IgnoringActor()); + await lookup('ignoring').send('dummy'); }); }); - test("constructor finishes before init() is run", async () => { + test('constructor finishes before init() is run', async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { constructor() { @@ -86,20 +111,20 @@ suite("Actor", () => { } onMessage() { } } - hookdown = await hookup("ignoring", new IgnoringActor()); + hookdown = await hookup('ignoring', new IgnoringActor()); }); }); - describe("initializeQueues", function () { - test("deletes old messages", async () => { + describe('initializeQueues', () => { + test('deletes old messages', async () => { await new Promise(async (resolve, reject) => { - await lookup("ignoring").send("dummy"); + await lookup('ignoring').send('dummy'); class IgnoringActor extends Actor { onMessage() { - reject(Error("Message got delivered anyway")); + reject(Error('Message got delivered anyway')); } } await initializeQueues(); - hookdown = await hookup("ignoring", new IgnoringActor()); + hookdown = await hookup('ignoring', new IgnoringActor()); setTimeout(resolve, 100); }); }); diff --git a/lib/actor/Actor_test.js.map b/lib/actor/Actor_test.js.map index 2ada6db..a096e72 100644 --- a/lib/actor/Actor_test.js.map +++ b/lib/actor/Actor_test.js.map @@ -1 +1 @@ -{"version":3,"file":"Actor_test.js","sourceRoot":"","sources":["../../src/actor/Actor_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAIrE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE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AC,CAAC;gBACvC,MAAM,aAAc,SAAQ,KAAc;oBACxC,SAAS;wBACP,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;oBAChD,CAAC;iBACF;gBACD,MAAM,gBAAgB,EAAE,CAAC;gBACzB,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,IAAI,aAAa,EAAE,CAAC,CAAC;gBACzD,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/watchable-message-store/WatchableMessageStore.d.ts b/lib/watchable-message-store/WatchableMessageStore.d.ts index 2e5fd92..1afab02 100644 --- a/lib/watchable-message-store/WatchableMessageStore.d.ts +++ b/lib/watchable-message-store/WatchableMessageStore.d.ts @@ -46,7 +46,7 @@ export declare class WatchableMessageStore { private bcc?; private dbName; private objStoreName; - private _lastCursorId; + lastCursorId: number; constructor(name: string); private init; /** diff --git a/lib/watchable-message-store/WatchableMessageStore.js b/lib/watchable-message-store/WatchableMessageStore.js index d88a6cb..04dbf34 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js +++ b/lib/watchable-message-store/WatchableMessageStore.js @@ -15,8 +15,8 @@ // 1 frame. E.g. this value needs to be higher than 16ms. Otherwise, the // IDB connection will starve and run into an endless loop. const POLLING_INTERVAL = 50; -const DB_PREFIX = 'ACTOR-DATABASE'; -const OBJECT_STORE_NAME = 'LIST'; +const DB_PREFIX = "ACTOR-DATABASE"; +const OBJECT_STORE_NAME = "LIST"; /** * A messageStore that can read and write to a specific objectStore in an * IndexedDB database. This class is used to implement message passing for @@ -32,10 +32,10 @@ export class WatchableMessageStore { constructor(name) { this.name = name; this.objStoreName = OBJECT_STORE_NAME; - this._lastCursorId = 0; + this.lastCursorId = 0; this.dbName = `${DB_PREFIX}.${name}`; this.database = this.init(); - if ('BroadcastChannel' in self) { + if ("BroadcastChannel" in self) { this.bcc = new BroadcastChannel(name); } } @@ -50,7 +50,9 @@ export class WatchableMessageStore { }; connection.onupgradeneeded = () => { if (!connection.result.objectStoreNames.contains(this.objStoreName)) { - connection.result.createObjectStore(this.objStoreName, { autoIncrement: true }); + connection.result.createObjectStore(this.objStoreName, { + autoIncrement: true + }); } }; }); @@ -65,9 +67,10 @@ export class WatchableMessageStore { * processed the message. */ async popMessages(recipient, { keepMessage = false } = {}) { - const transaction = (await this.database).transaction(this.objStoreName, 'readwrite'); - const cursorRequest = transaction.objectStore(this.objStoreName) - .openCursor(IDBKeyRange.lowerBound(this._lastCursorId, true)); + const transaction = (await this.database).transaction(this.objStoreName, "readwrite"); + const cursorRequest = transaction + .objectStore(this.objStoreName) + .openCursor(IDBKeyRange.lowerBound(this.lastCursorId, true)); return new Promise((resolve, reject) => { const messages = []; cursorRequest.onerror = () => { @@ -77,14 +80,14 @@ export class WatchableMessageStore { const cursor = cursorRequest.result; if (cursor) { const value = cursor.value; - if (value.recipient === recipient || recipient === '*') { + if (value.recipient === recipient || recipient === "*") { messages.push(value); if (!keepMessage) { cursor.delete(); } } cursor.continue(); - this._lastCursorId = cursor.key; + this.lastCursorId = cursor.key; } else { resolve(messages); @@ -98,17 +101,19 @@ export class WatchableMessageStore { * @param message The message to store with a recipient and a detail. */ async pushMessage(message) { - if (message.recipient === '*') { - throw new Error('Can’t send a message to reserved name \'*\''); + if (message.recipient === "*") { + throw new Error("Can’t send a message to reserved name '*'"); } - const transaction = (await this.database).transaction(this.objStoreName, 'readwrite'); + const transaction = (await this.database).transaction(this.objStoreName, "readwrite"); return new Promise((resolve, reject) => { transaction.onerror = () => { reject(transaction.error); }; transaction.oncomplete = () => { if (this.bcc) { - this.bcc.postMessage({ recipient: message.recipient }); + this.bcc.postMessage({ + recipient: message.recipient + }); } resolve(); }; @@ -127,9 +132,9 @@ export class WatchableMessageStore { callback(messages); } }; - channel.addEventListener('message', channelCallback); + channel.addEventListener("message", channelCallback); // Check for already stored messages immediately - channelCallback(new MessageEvent('message', { data: { recipient } })); + channelCallback(new MessageEvent("message", { data: { recipient } })); return () => { channel.close(); }; @@ -160,7 +165,7 @@ export class WatchableMessageStore { */ subscribe(recipient, callback) { let unsubscribe = null; - if ('BroadcastChannel' in self) { + if ("BroadcastChannel" in self) { unsubscribe = this.subscribeWithBroadcastChannel(recipient, callback); } else { diff --git a/lib/watchable-message-store/WatchableMessageStore.js.map b/lib/watchable-message-store/WatchableMessageStore.js.map index 583d551..d1ce4cc 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js.map +++ b/lib/watchable-message-store/WatchableMessageStore.js.map @@ -1 +1 @@ -{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAqBjC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAOhC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAHxB,iBAAY,GAAG,iBAAiB,CAAC;QACjC,kBAAa,GAAG,CAAC,CAAC;QAGxB,IAAI,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACvC;IACH,CAAC;IAEO,IAAI;QACV,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,UAAU,GAAG,SAAS,CAAC,I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QAEF,OAAO,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;QAErD,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,SAAiB,EAAE,QAA6C;QACxE,IAAI,WAAW,GAAG,IAAI,CAAC;QAEvB,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,WAAW,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SACvE;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC9D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file +{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAqBjC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAOhC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAHxB,iBAAY,GAAG,iBAAiB,CAAC;QACzC,iBAAY,GAAG,CAAC,CAAC;QAGf,IAAI,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACvC;IACH,CAAC;IAEO,IAAI;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CAAC,QAAQ,CAAC,CAAC;aACpB;YACD,OAAO,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;QACvD,CAAC,CAAC;QAEF,OAAO,GAAG,UAAU,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;QAErD,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,SAAiB,EAAE,QAA6C;QACxE,IAAI,WAAW,GAAG,IAAI,CAAC;QAEvB,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,WAAW,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SACvE;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC9D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file diff --git a/src/actor/Actor.ts b/src/actor/Actor.ts index 61987ba..6328abe 100644 --- a/src/actor/Actor.ts +++ b/src/actor/Actor.ts @@ -31,7 +31,8 @@ declare global { * } * * If an actor can receive multiple types of messages, - * [a discriminated union](https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions) + * [a discriminated + * union](https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions) * has proven useful. */ interface ActorMessageType {} @@ -78,7 +79,8 @@ interface Constructable { * * onMessage(message: MessageType) { * this.count!++; - * console.log(`Actor ${this.actorName} received message number ${this.count}: ${message}`); + * console.log(`Actor ${this.actorName} received message number + * ${this.count}: ${message}`); * } * } * @@ -94,7 +96,8 @@ export function actorMixin>( ) { return class extends superClass { /** - * Do not use, it is an internal implementation detail used in {@link hookup}. + * Do not use, it is an internal implementation detail used in {@link + * hookup}. */ readonly initPromise = Promise.resolve().then(() => this.init()); @@ -180,7 +183,8 @@ export function actorMixin>( * * onMessage(message: MessageType) { * this.count!++; - * console.log(`Actor ${this.actorName} received message number ${this.count}: ${message}`); + * console.log(`Actor ${this.actorName} received message number + * ${this.count}: ${message}`); * } * } * @@ -239,6 +243,8 @@ export async function hookup( // @ts-ignore await actor.initPromise; + messageStore.lastCursorId = 0; + if (purgeExistingMessages) { await messageStore.popMessages(actorName); } @@ -327,10 +333,7 @@ export function lookup( ): ActorHandle { return { async send(message: ActorMessageType[ActorName]) { - await messageStore.pushMessage({ - recipient: actorName, - detail: message - }); + await messageStore.pushMessage({ recipient: actorName, detail: message }); } }; } diff --git a/src/actor/Actor_test.ts b/src/actor/Actor_test.ts index 7302160..1b3ea39 100644 --- a/src/actor/Actor_test.ts +++ b/src/actor/Actor_test.ts @@ -12,7 +12,13 @@ * http://polymer.github.io/PATENTS.txt */ -import { Actor, hookup, lookup, initializeQueues } from "./Actor.js"; +import { + Actor, + HookdownCallback, + hookup, + initializeQueues, + lookup +} from "./Actor.js"; declare var window: { Mocha: Mocha.MochaGlobals; assert: Chai.Assert }; @@ -30,7 +36,7 @@ declare global { suite("Actor", () => { let hookdown: () => void; - setup(async function() { + setup(async () => { await initializeQueues(); }); @@ -83,6 +89,35 @@ suite("Actor", () => { }); }); + test("re-traverses messages after hookup", async () => { + await new Promise(async resolve => { + let ignoringHookdown: HookdownCallback; + + class LateActor extends Actor<"dummy"> { + onMessage() { + resolve(); + } + } + + class IgnoringActor extends Actor<"dummy"> { + onMessage() { + setTimeout(async () => { + const lateHookdown = await hookup("late", new LateActor()); + + hookdown = async () => { + await ignoringHookdown(); + await lateHookdown(); + }; + }, 100); + } + } + + await lookup("late").send("dummy"); + await lookup("ignoring").send("dummy"); + ignoringHookdown = await hookup("ignoring", new IgnoringActor()); + }); + }); + test("can retrieve own actor name", async () => { await new Promise(async resolve => { class IgnoringActor extends Actor<"dummy"> { @@ -121,7 +156,7 @@ suite("Actor", () => { }); }); - describe("initializeQueues", function() { + describe("initializeQueues", () => { test("deletes old messages", async () => { await new Promise(async (resolve, reject) => { await lookup("ignoring").send("dummy"); diff --git a/src/watchable-message-store/WatchableMessageStore.ts b/src/watchable-message-store/WatchableMessageStore.ts index 5e9491d..caaa502 100644 --- a/src/watchable-message-store/WatchableMessageStore.ts +++ b/src/watchable-message-store/WatchableMessageStore.ts @@ -60,7 +60,7 @@ export class WatchableMessageStore { private bcc?: BroadcastChannel; private dbName: string; private objStoreName = OBJECT_STORE_NAME; - private _lastCursorId = 0; + lastCursorId = 0; constructor(private name: string) { this.dbName = `${DB_PREFIX}.${name}`; @@ -117,7 +117,7 @@ export class WatchableMessageStore { const cursorRequest = transaction .objectStore(this.objStoreName) - .openCursor(IDBKeyRange.lowerBound(this._lastCursorId, true)); + .openCursor(IDBKeyRange.lowerBound(this.lastCursorId, true)); return new Promise((resolve, reject) => { const messages: StoredMessage[] = []; @@ -142,7 +142,7 @@ export class WatchableMessageStore { cursor.continue(); - this._lastCursorId = cursor.key as number; + this.lastCursorId = cursor.key as number; } else { resolve(messages); } From 4a4ede5dec60842b2026eb6f5791c6521de72b35 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 29 Nov 2018 16:16:47 +0000 Subject: [PATCH 3/3] Add resetCursor --- lib/actor/Actor.js | 8 +-- lib/actor/Actor.js.map | 2 +- lib/actor/Actor_test.d.ts | 6 +- lib/actor/Actor_test.js | 55 +++++++++---------- lib/actor/Actor_test.js.map | 2 +- .../WatchableMessageStore.d.ts | 3 +- .../WatchableMessageStore.js | 3 + .../WatchableMessageStore.js.map | 2 +- src/actor/Actor.ts | 2 +- .../WatchableMessageStore.ts | 6 +- 10 files changed, 48 insertions(+), 41 deletions(-) diff --git a/lib/actor/Actor.js b/lib/actor/Actor.js index d6955a2..e49b9c5 100644 --- a/lib/actor/Actor.js +++ b/lib/actor/Actor.js @@ -11,7 +11,7 @@ * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -import { WatchableMessageStore } from '../watchable-message-store/WatchableMessageStore.js'; +import { WatchableMessageStore } from "../watchable-message-store/WatchableMessageStore.js"; /** * A mixin function to define an Actor type. It creates a class with a stub * for the {@link Actor#onMessage} callback, which must be overwritten. @@ -150,7 +150,7 @@ export function actorMixin(superClass) { export class Actor extends actorMixin(Object) { async init() { } } -const messageStore = new WatchableMessageStore('ACTOR-MESSAGES'); +const messageStore = new WatchableMessageStore("ACTOR-MESSAGES"); /** * Hookup an {@link Actor} with a name into system. In this case, the actor * will initialize and respond to any messages designated for `actorName`. @@ -181,7 +181,7 @@ export async function hookup(actorName, actor, { purgeExistingMessages = false } actor.actorName = actorName; // @ts-ignore await actor.initPromise; - messageStore.lastCursorId = 0; + messageStore.resetCursor(); if (purgeExistingMessages) { await messageStore.popMessages(actorName); } @@ -272,6 +272,6 @@ export function lookup(actorName) { * hookup("database", new DatabaseActor()); */ export async function initializeQueues() { - await messageStore.popMessages('*'); + await messageStore.popMessages("*"); } //# sourceMappingURL=Actor.js.map \ No newline at end of file diff --git a/lib/actor/Actor.js.map b/lib/actor/Actor.js.map index 243f678..b14cab1 100644 --- a/lib/actor/Actor.js.map +++ b/lib/actor/Actor.js.map @@ -1 +1 @@ -{"version":3,"file":"Actor.js","sourceRoot":"","sources":["../../src/actor/Actor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAC,qBAAqB,EAAC,MAAM,qDAAqD,CAAC;AAyC1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,UAAU,CACtB,UAAa;IACf,OAAO,KAAM,SAAQ,UAAU;QAAxB;;YACL;;;eAGG;YACM,gBAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAyDnE,CAAC;QAlDC;;;;;;;;;WASG;QACH,KAAK,CAAC,IAAI,KAAmB,CAAC;QAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAkCG;Q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AAW,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/lib/actor/Actor_test.d.ts b/lib/actor/Actor_test.d.ts index f39dbcc..fb7df17 100644 --- a/lib/actor/Actor_test.d.ts +++ b/lib/actor/Actor_test.d.ts @@ -13,9 +13,9 @@ */ declare global { interface ActorMessageType { - ignoring: 'dummy'; - ignoring1: 'foo'; - late: 'dummy'; + ignoring: "dummy"; + ignoring1: "foo"; + late: "dummy"; } } export {}; diff --git a/lib/actor/Actor_test.js b/lib/actor/Actor_test.js index 197e808..2e144ff 100644 --- a/lib/actor/Actor_test.js +++ b/lib/actor/Actor_test.js @@ -11,10 +11,10 @@ * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -import { Actor, hookup, initializeQueues, lookup } from './Actor.js'; +import { Actor, hookup, initializeQueues, lookup } from "./Actor.js"; const { suite, test, teardown, setup } = window.Mocha; const { assert } = window; -suite('Actor', () => { +suite("Actor", () => { let hookdown; setup(async () => { await initializeQueues(); @@ -24,54 +24,53 @@ suite('Actor', () => { await hookdown(); } }); - test('can hookup an actor', async () => { + test("can hookup an actor", async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - hookdown = await hookup('ignoring1', new IgnoringActor()); - await lookup('ignoring1').send('foo'); + hookdown = await hookup("ignoring1", new IgnoringActor()); + await lookup("ignoring1").send("foo"); }); }); - test('can lookup an actor and send a message', async () => { + test("can lookup an actor and send a message", async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - hookdown = await hookup('ignoring', new IgnoringActor()); - await lookup('ignoring').send('dummy'); + hookdown = await hookup("ignoring", new IgnoringActor()); + await lookup("ignoring").send("dummy"); }); }); - test('can call lookup before hookup', async () => { + test("can call lookup before hookup", async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { resolve(); } } - await lookup('ignoring').send('dummy'); + await lookup("ignoring").send("dummy"); setTimeout(async () => { - hookdown = await hookup('ignoring', new IgnoringActor()); + hookdown = await hookup("ignoring", new IgnoringActor()); }, 100); }); }); - test('re-traverses messages after hookup', async () => { + test("re-traverses messages after hookup", async () => { await new Promise(async (resolve) => { let ignoringHookdown; class LateActor extends Actor { onMessage() { - console.log('late called'); resolve(); } } class IgnoringActor extends Actor { onMessage() { setTimeout(async () => { - const lateHookdown = await hookup('late', new LateActor()); + const lateHookdown = await hookup("late", new LateActor()); hookdown = async () => { await ignoringHookdown(); await lateHookdown(); @@ -79,24 +78,24 @@ suite('Actor', () => { }, 100); } } - await lookup('late').send('dummy'); - await lookup('ignoring').send('dummy'); - ignoringHookdown = await hookup('ignoring', new IgnoringActor()); + await lookup("late").send("dummy"); + await lookup("ignoring").send("dummy"); + ignoringHookdown = await hookup("ignoring", new IgnoringActor()); }); }); - test('can retrieve own actor name', async () => { + test("can retrieve own actor name", async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { onMessage() { - assert.equal(this.actorName, 'ignoring'); + assert.equal(this.actorName, "ignoring"); resolve(); } } - hookdown = await hookup('ignoring', new IgnoringActor()); - await lookup('ignoring').send('dummy'); + hookdown = await hookup("ignoring", new IgnoringActor()); + await lookup("ignoring").send("dummy"); }); }); - test('constructor finishes before init() is run', async () => { + test("constructor finishes before init() is run", async () => { await new Promise(async (resolve) => { class IgnoringActor extends Actor { constructor() { @@ -111,20 +110,20 @@ suite('Actor', () => { } onMessage() { } } - hookdown = await hookup('ignoring', new IgnoringActor()); + hookdown = await hookup("ignoring", new IgnoringActor()); }); }); - describe('initializeQueues', () => { - test('deletes old messages', async () => { + describe("initializeQueues", () => { + test("deletes old messages", async () => { await new Promise(async (resolve, reject) => { - await lookup('ignoring').send('dummy'); + await lookup("ignoring").send("dummy"); class IgnoringActor extends Actor { onMessage() { - reject(Error('Message got delivered anyway')); + reject(Error("Message got delivered anyway")); } } await initializeQueues(); - hookdown = await hookup('ignoring', new IgnoringActor()); + hookdown = await hookup("ignoring", new IgnoringActor()); setTimeout(resolve, 100); }); }); diff --git a/lib/actor/Actor_test.js.map b/lib/actor/Actor_test.js.map index a096e72..c55bb47 100644 --- a/lib/actor/Actor_test.js.map +++ b/lib/actor/Actor_test.js.map @@ -1 +1 @@ -{"version":3,"file":"Actor_test.js","sourceRoot":"","sources":["../../src/actor/Actor_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAC,KAAK,EAAoB,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAIrF,MAAM,EAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAC,GAAG,MAAM,CAAC,KAAK,CAAC;AACpD,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,CAAC;AAUxB,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE;IAClB,IAAI,QAAoB,CAAC;IAEzB,KAAK,CAAC,KAAK,IAAI,EAAE;QACf,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,EAAE,CAAC;SAClB;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACrC,MAAM,IAAI,OAAO,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;YAChC,MAAM,aAAc,SAAQ,KAAY;gBACtC,SAAS;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;aACF;YAED,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,IAAI,aAAa,EAAE,CAAC,CAAC;YAC1D,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,IAAI,OAAO,CAAC,KAAK,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,OAAO,CAAC,CAAC;gBACvC,MAAM,aAAc,SAAQ,KAAc;oBACxC,SAAS;wBACP,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;oBAChD,CAAC;iBACF;gBACD,MAAM,gBAAgB,EAAE,CAAC;gBACzB,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,IAAI,aAAa,EAAE,CAAC,CAAC;gBACzD,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/watchable-message-store/WatchableMessageStore.d.ts b/lib/watchable-message-store/WatchableMessageStore.d.ts index 1afab02..a98ad5b 100644 --- a/lib/watchable-message-store/WatchableMessageStore.d.ts +++ b/lib/watchable-message-store/WatchableMessageStore.d.ts @@ -46,8 +46,9 @@ export declare class WatchableMessageStore { private bcc?; private dbName; private objStoreName; - lastCursorId: number; + private lastCursorId; constructor(name: string); + resetCursor(): void; private init; /** * Retrieve all messages for a specific recipient. You can specify with diff --git a/lib/watchable-message-store/WatchableMessageStore.js b/lib/watchable-message-store/WatchableMessageStore.js index 04dbf34..c9c2c06 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js +++ b/lib/watchable-message-store/WatchableMessageStore.js @@ -39,6 +39,9 @@ export class WatchableMessageStore { this.bcc = new BroadcastChannel(name); } } + resetCursor() { + this.lastCursorId = 0; + } init() { return new Promise((resolve, reject) => { const connection = indexedDB.open(this.dbName); diff --git a/lib/watchable-message-store/WatchableMessageStore.js.map b/lib/watchable-message-store/WatchableMessageStore.js.map index d1ce4cc..d3e1bbf 100644 --- a/lib/watchable-message-store/WatchableMessageStore.js.map +++ b/lib/watchable-message-store/WatchableMessageStore.js.map @@ -1 +1 @@ -{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"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CAAC;IACrB,CAAC;CACF"} \ No newline at end of file +{"version":3,"file":"WatchableMessageStore.js","sourceRoot":"","sources":["../../src/watchable-message-store/WatchableMessageStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAqBjC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IAOhC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAHxB,iBAAY,GAAG,iBAAiB,CAAC;QACjC,iBAAY,GAAG,CAAC,CAAC;QAGvB,IAAI,CAAC,MAAM,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,kBAAkB,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACvC;IACH,CAAC;IAED,WAAW;QACT,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;IACxB,CAAC;IAEO,IAAI;QACV,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE/C,UAAU,CAAC,OAAO,GAAG,GAAG,EAAE;gBACxB,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC;YAEF,UAAU,CAAC,SAAS,GAAG,GAAG,EAAE;gBAC1B,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC,CAAC;YAEF,UAAU,CAAC,eAAe,GAAG,GAAG,EAAE;gBAChC,IAA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,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SACvE;aAAM;YACL,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC9D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file diff --git a/src/actor/Actor.ts b/src/actor/Actor.ts index 6328abe..d6f23b2 100644 --- a/src/actor/Actor.ts +++ b/src/actor/Actor.ts @@ -243,7 +243,7 @@ export async function hookup( // @ts-ignore await actor.initPromise; - messageStore.lastCursorId = 0; + messageStore.resetCursor(); if (purgeExistingMessages) { await messageStore.popMessages(actorName); diff --git a/src/watchable-message-store/WatchableMessageStore.ts b/src/watchable-message-store/WatchableMessageStore.ts index caaa502..49c7f3c 100644 --- a/src/watchable-message-store/WatchableMessageStore.ts +++ b/src/watchable-message-store/WatchableMessageStore.ts @@ -60,7 +60,7 @@ export class WatchableMessageStore { private bcc?: BroadcastChannel; private dbName: string; private objStoreName = OBJECT_STORE_NAME; - lastCursorId = 0; + private lastCursorId = 0; constructor(private name: string) { this.dbName = `${DB_PREFIX}.${name}`; @@ -71,6 +71,10 @@ export class WatchableMessageStore { } } + resetCursor() { + this.lastCursorId = 0; + } + private init() { return new Promise((resolve, reject) => { const connection = indexedDB.open(this.dbName);