Skip to content

Commit 2da7fed

Browse files
committed
Cursed working example
1 parent 4cb9cf4 commit 2da7fed

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/core/reactor.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@ export abstract class Reactor extends Component {
435435
if (src instanceof CallerPort && dst instanceof CalleePort) {
436436
this.reactor._connectCall(src, dst);
437437
} else if (src instanceof IOPort && dst instanceof IOPort) {
438-
this.reactor._connect(src, dst);
438+
try {
439+
this.reactor._connect(src, dst);
440+
} catch (error) {
441+
console.log(`[DEBUG] MutationSandbox.connect: Regular connect failed: ${(error as Error).message}}, trying elevated connect`);
442+
this.reactor._elevatedConnect(src, dst);
443+
}
439444
} else {
440445
// ERROR
441446
}
@@ -1226,10 +1231,10 @@ export abstract class Reactor extends Component {
12261231
dst: IOPort<R>
12271232
): void {
12281233
Log.debug(this, () => `connecting ${src} and ${dst}`);
1229-
// Add dependency implied by connection to local graph.
1230-
this._dependencyGraph.addEdge(src, dst);
12311234
// Register receiver for value propagation.
12321235
const writer = dst.asWritable(this._getKey(dst));
1236+
// Add dependency implied by connection to local graph.
1237+
this._dependencyGraph.addEdge(src, dst);
12331238
src
12341239
.getManager(this._getKey(src))
12351240
.addReceiver(writer as unknown as WritablePort<S>);
@@ -1576,6 +1581,29 @@ export abstract class Reactor extends Component {
15761581
}
15771582
return this._getContainer()._uncheckedAddChild(constructor, ...args);
15781583
}
1584+
1585+
public _elevatedConnect(...args: Parameters<Reactor["_connect"]>): ReturnType<Reactor["_connect"]> {
1586+
// eslint-disable-next-line @typescript-eslint/no-this-alias
1587+
let currentLevel: Reactor = this;
1588+
let atTopLevel = false;
1589+
while (currentLevel != null && !atTopLevel) {
1590+
console.log(`[DEBUG] _elevatedConnect: I am ${currentLevel}, my parent is ${currentLevel._getContainer()}`);
1591+
console.log(`[DEBUG] _elevatedConnect: ${currentLevel != null && currentLevel._getContainer() !== currentLevel ? "yes" : "no"}`)
1592+
if (currentLevel === currentLevel._getContainer()) {
1593+
atTopLevel = true;
1594+
}
1595+
console.log(`[DEBUG] _elevatedConnect: Attempting connection from ${currentLevel}`)
1596+
try {
1597+
currentLevel._connect(...args);
1598+
return
1599+
} catch (error) {
1600+
console.log(`[DEBUG] _elevatedConnect: Error - ${(error as Error).message}`)
1601+
}
1602+
currentLevel = currentLevel._getContainer();
1603+
console.log(`[DEBUG] next level ${currentLevel}`)
1604+
}
1605+
throw new Error(`[DEBUG] _elevatedConnect: Elevated connect failed for ${this._getFullyQualifiedName()}.`);
1606+
}
15791607
}
15801608

15811609
/*

0 commit comments

Comments
 (0)