This commit is contained in:
Tony Garnock-Jones 2021-02-22 20:45:19 +01:00
parent fa98a399bc
commit eb24199c8b
2 changed files with 5 additions and 10 deletions

View File

@ -55,10 +55,6 @@ export class Actor {
}
}
ref<T>(t: T): Ref<T> {
return new Ref(this, t);
}
execute(proc: () => void): void {
queueMicrotask(() => {
if (this.alive) {
@ -101,7 +97,7 @@ export class Turn {
}
ref<T>(t: T, what: string = "ref"): Ref<T> {
return this._ensureActor(what).ref(t);
return new Ref(this._ensureActor(what), t);
}
spawn(bootProc: (t: Turn) => void, initialAssertions?: IdentitySet<Handle>): void {

View File

@ -14,7 +14,7 @@ import { Bag, ChangeDescription } from './bag';
const Observe = Record.makeConstructor<Ref<Entity>>('Observe', ['label', 'observer']);
function makeDataspace(): Ref<Entity> {
function makeDataspace(): Entity {
const handleMap: IdentityMap<Handle, Assertion> = new IdentityMap();
const assertions = new Bag<Ref<Entity>>();
const subscriptions: Dictionary<Dictionary<Dictionary<Handle>>> = new Dictionary();
@ -32,8 +32,7 @@ function makeDataspace(): Ref<Entity> {
}
}
const a = new Actor();
return a.ref<Entity>({
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<Entity> {
// console.log(`DS: message ${message.asPreservesText()}`);
forEachSubscription(message, (_handleMap, peer) => turn.message(peer, message));
}
});
};
}
const BoxState = Record.makeConstructor<Ref<Entity>>('BoxState', ['value']);
@ -99,7 +98,7 @@ const SetBox = Record.makeConstructor<Ref<Entity>>('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 => {