Dataspace.boot

This commit is contained in:
Tony Garnock-Jones 2021-12-09 22:12:41 +01:00
parent 6d7dbaf3b3
commit e0d76f8dd3
3 changed files with 13 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import {
Pattern as P,
assertObserve,
Record,
Actor, Dataspace, Turn,
Dataspace, Turn,
} from '..';
const BoxState = Record.makeConstructor()(Symbol.for('BoxState'), ['value']);
@ -16,10 +16,7 @@ const N = 100000;
console.time('box-and-client-' + N.toString());
Actor.boot(() => {
Turn.activeFacet.preventInertCheck();
const ds = Turn.ref(new Dataspace());
Dataspace.boot(ds => {
Turn.active.spawn(() => {
Turn.activeFacet.actor.name = 'box';
const boxValue = Turn.active.field(0, 'value');

View File

@ -6,7 +6,7 @@ import {
Pattern as P,
assertObserve,
Record,
Actor, Dataspace, Turn,
Dataspace, Turn,
} from '..';
const BoxState = Record.makeConstructor<{value: number}>()(Symbol.for('BoxState'), ['value']);
@ -16,10 +16,7 @@ const N = 100000;
console.time('box-and-client-' + N.toString());
Actor.boot(() => {
Turn.activeFacet.preventInertCheck();
const ds = Turn.ref(new Dataspace());
Dataspace.boot(ds => {
Turn.active.spawn(() => {
Turn.activeFacet.actor.name = 'box';
const boxValue = Turn.active.field<number>(0, 'value');

View File

@ -3,7 +3,7 @@
import { IdentityMap, stringify } from '@preserves/core';
import { Index } from './skeleton.js';
import { Assertion, Entity, Facet, Handle, LocalAction, Ref, Turn } from './actor.js';
import { Actor, Assertion, Entity, Facet, Handle, LocalAction, Ref, Turn } from './actor.js';
import { fromObserve, Observe, toObserve } from '../gen/dataspace.js';
import * as P from '../gen/dataspacePatterns.js';
@ -38,6 +38,14 @@ export class Dataspace implements Partial<Entity> {
// console.log('!', stringify(v));
this.index.deliverMessage(v);
}
static boot(bootProc: (ds: Ref) => void): Actor {
return Actor.boot(() => {
Turn.activeFacet.preventInertCheck();
const ds = Turn.active.ref(new Dataspace());
bootProc(ds);
});
}
}
export function assertionObserver(f: (a: Assertion) => LocalAction | undefined): Partial<Entity> {