diff --git a/packages/core/examples/box-and-client.js b/packages/core/examples/box-and-client.js index 1e17afb..4058c9b 100644 --- a/packages/core/examples/box-and-client.js +++ b/packages/core/examples/box-and-client.js @@ -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'); diff --git a/packages/core/examples/box-and-client.ts b/packages/core/examples/box-and-client.ts index 3134946..b6f7c6b 100644 --- a/packages/core/examples/box-and-client.ts +++ b/packages/core/examples/box-and-client.ts @@ -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(0, 'value'); diff --git a/packages/core/src/runtime/dataspace.ts b/packages/core/src/runtime/dataspace.ts index cb6ca7e..9a7ed18 100644 --- a/packages/core/src/runtime/dataspace.ts +++ b/packages/core/src/runtime/dataspace.ts @@ -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 { // 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 {