No need to spawn a relay
This commit is contained in:
parent
a9a3a8a66d
commit
f24dfb53d5
|
@ -118,6 +118,9 @@ export interface RelayOptions {
|
||||||
setup(r: Relay): void;
|
setup(r: Relay): void;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
trustPeer?: boolean;
|
trustPeer?: boolean;
|
||||||
|
initialOid?: IO.Oid;
|
||||||
|
initialRef?: Ref;
|
||||||
|
nextLocalOid?: IO.Oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Relay {
|
export class Relay {
|
||||||
|
@ -130,6 +133,7 @@ export class Relay {
|
||||||
readonly outboundAssertions = new IdentityMap<Handle, Array<WireSymbol>>();
|
readonly outboundAssertions = new IdentityMap<Handle, Array<WireSymbol>>();
|
||||||
readonly exported = new Membrane();
|
readonly exported = new Membrane();
|
||||||
readonly imported = new Membrane();
|
readonly imported = new Membrane();
|
||||||
|
readonly peer: Ref | null;
|
||||||
nextLocalOid: IO.Oid = 0;
|
nextLocalOid: IO.Oid = 0;
|
||||||
pendingTurn: IO.Turn<WireRef> = [];
|
pendingTurn: IO.Turn<WireRef> = [];
|
||||||
debug: boolean;
|
debug: boolean;
|
||||||
|
@ -148,6 +152,18 @@ export class Relay {
|
||||||
|
|
||||||
this.facet.preventInertCheck();
|
this.facet.preventInertCheck();
|
||||||
options.setup(this);
|
options.setup(this);
|
||||||
|
|
||||||
|
if (options.initialRef !== void 0) {
|
||||||
|
this.rewriteRefOut(options.initialRef, false, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.peer = (options.initialOid !== void 0)
|
||||||
|
? this.rewriteRefIn(WireRef.mine(options.initialOid), [])
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (options.nextLocalOid !== void 0) {
|
||||||
|
this.nextLocalOid = (options.nextLocalOid === 0) ? 1 : options.nextLocalOid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rewriteOut(assertion: Assertion, transient: boolean): [Value<WireRef>, Array<WireSymbol>]
|
rewriteOut(assertion: Assertion, transient: boolean): [Value<WireRef>, Array<WireSymbol>]
|
||||||
|
@ -301,31 +317,3 @@ export class Relay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RelayActorOptions extends RelayOptions {
|
|
||||||
initialOid?: IO.Oid;
|
|
||||||
initialRef?: Ref;
|
|
||||||
nextLocalOid?: IO.Oid;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function spawnRelay(options: RelayActorOptions & {initialOid: IO.Oid}): Promise<Ref>;
|
|
||||||
export function spawnRelay(options: Omit<RelayActorOptions, 'initialOid'>): Promise<null>;
|
|
||||||
export function spawnRelay(options: RelayActorOptions): Promise<Ref | null>
|
|
||||||
{
|
|
||||||
return new Promise(resolve => {
|
|
||||||
Turn.active.spawn(() => {
|
|
||||||
const relay = new Relay(options);
|
|
||||||
if (options.initialRef !== void 0) {
|
|
||||||
relay.rewriteRefOut(options.initialRef, false, []);
|
|
||||||
}
|
|
||||||
if (options.initialOid !== void 0) {
|
|
||||||
resolve(relay.rewriteRefIn(WireRef.mine(options.initialOid), []));
|
|
||||||
} else {
|
|
||||||
resolve(null);
|
|
||||||
}
|
|
||||||
if (options.nextLocalOid !== void 0) {
|
|
||||||
relay.nextLocalOid = (options.nextLocalOid === 0) ? 1 : options.nextLocalOid;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue