diff --git a/actor.ts b/actor.ts index 8b5f0d2..8f055b6 100644 --- a/actor.ts +++ b/actor.ts @@ -11,9 +11,9 @@ export const retract = Symbol('retract'); export const message = Symbol('message'); export interface Entity { - [assert](turn: Turn, assertion: Assertion, handle: Handle): void; - [retract](turn: Turn, handle: Handle): void; - [message](turn: Turn, message: Assertion): void; + [assert]?(turn: Turn, assertion: Assertion, handle: Handle): void; + [retract]?(turn: Turn, handle: Handle): void; + [message]?(turn: Turn, message: Assertion): void; } export class Ref { @@ -104,10 +104,6 @@ export class Turn { return this._ensureActor(what).ref(t); } - entity(t: Partial): Ref { - return this.ref({ ... NULL_ENTITY, ... t }, "entity"); - } - spawn(bootProc: (t: Turn) => void, initialAssertions?: IdentitySet): void { if ((initialAssertions !== void 0) && (initialAssertions.size > 0)) { this._ensureActor("spawn with initialAssertions"); @@ -131,7 +127,7 @@ export class Turn { const h = nextHandle++; this.enqueue(location.actor, t => { this.actor!.outbound.set(h, [location, assertion]); - location.target[assert](t, assertion, h); + location.target[assert]?.(t, assertion, h); }); return h; } @@ -149,7 +145,7 @@ export class Turn { _retract(location: Ref, handle: Handle): void { this.enqueue(location.actor, t => { this.actor!.outbound.delete(handle); - location.target[retract](t, handle); + location.target[retract]?.(t, handle); }); } @@ -160,7 +156,7 @@ export class Turn { } message(location: Ref, assertion: Assertion): void { - this.enqueue(location.actor, t => location.target[message](t, assertion)); + this.enqueue(location.actor, t => location.target[message]?.(t, assertion)); } enqueue(actor: Actor, a: LocalAction): void { @@ -185,12 +181,6 @@ export class Turn { } } -export const NULL_ENTITY: Entity = { - [assert](_t: Turn, _assertion: Assertion, _handle: Handle): void {}, - [retract](_t: Turn, _handle: Handle): void {}, - [message](_t: Turn, _assertion: Assertion): void {}, -}; - function extractFromMap(map: Map, keys?: IdentitySet): Map { const result: Map = new Map(); if (keys !== void 0) { diff --git a/main.ts b/main.ts index 0187821..0ef0399 100644 --- a/main.ts +++ b/main.ts @@ -111,7 +111,7 @@ Turn.for(null, async (t: Turn) => { valueHandle = t.replace(ds, valueHandle, BoxState(value)); } setValue(t, 0); - t.assert(ds, Observe(SetBox.constructorInfo.label, t.entity({ + t.assert(ds, Observe(SetBox.constructorInfo.label, t.ref({ [message](t: Turn, [newValue]: [number]): void { if (newValue % 25000 === 0) { const endTime = Date.now(); @@ -131,7 +131,7 @@ Turn.for(null, async (t: Turn) => { t.spawn(t => { console.log('Spawning Client'); let count = 0; - t.assert(ds, Observe(BoxState.constructorInfo.label, t.entity({ + t.assert(ds, Observe(BoxState.constructorInfo.label, t.ref({ [assert](t: Turn, [currentValue]: [number]): void { // console.log(`Client: got ${currentValue}`); if (currentValue === 300000) { @@ -142,7 +142,7 @@ Turn.for(null, async (t: Turn) => { } } }))); - t.assert(ds, Observe(BoxState.constructorInfo.label, t.entity({ + t.assert(ds, Observe(BoxState.constructorInfo.label, t.ref({ [assert](_t: Turn, _assertion: Assertion): void { count++; }, [retract](t: Turn, _handle: Handle) { if (--count === 0) {