From eb24199c8be87ba9006b1d92c5b9d3d2870a2a91 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 22 Feb 2021 20:45:19 +0100 Subject: [PATCH] Simplify --- actor.ts | 6 +----- main.ts | 9 ++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/actor.ts b/actor.ts index 8f055b6..8742c88 100644 --- a/actor.ts +++ b/actor.ts @@ -55,10 +55,6 @@ export class Actor { } } - ref(t: T): Ref { - return new Ref(this, t); - } - execute(proc: () => void): void { queueMicrotask(() => { if (this.alive) { @@ -101,7 +97,7 @@ export class Turn { } ref(t: T, what: string = "ref"): Ref { - return this._ensureActor(what).ref(t); + return new Ref(this._ensureActor(what), t); } spawn(bootProc: (t: Turn) => void, initialAssertions?: IdentitySet): void { diff --git a/main.ts b/main.ts index 0ef0399..84f0314 100644 --- a/main.ts +++ b/main.ts @@ -14,7 +14,7 @@ import { Bag, ChangeDescription } from './bag'; const Observe = Record.makeConstructor>('Observe', ['label', 'observer']); -function makeDataspace(): Ref { +function makeDataspace(): Entity { const handleMap: IdentityMap = new IdentityMap(); const assertions = new Bag>(); const subscriptions: Dictionary>> = new Dictionary(); @@ -32,8 +32,7 @@ function makeDataspace(): Ref { } } - const a = new Actor(); - return a.ref({ + return { [assert](turn: Turn, assertion: Assertion, handle: Handle): void { // console.log(`DS: assert ${assertion.asPreservesText()} :: ${handle}`); handleMap.set(handle, assertion); @@ -90,7 +89,7 @@ function makeDataspace(): Ref { // console.log(`DS: message ${message.asPreservesText()}`); forEachSubscription(message, (_handleMap, peer) => turn.message(peer, message)); } - }); + }; } const BoxState = Record.makeConstructor>('BoxState', ['value']); @@ -99,7 +98,7 @@ const SetBox = Record.makeConstructor>('SetBox', ['newValue']); let startTime = Date.now(); let prevValue = 0; Turn.for(null, async (t: Turn) => { - const ds = makeDataspace(); + const ds = new Ref(new Actor(), makeDataspace()); // Box t.spawn(t => {