Skip to content

Commit b0bf368

Browse files
committed
Restructure canconnect; mutationsandbox.connect
1 parent 2da7fed commit b0bf368

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/core/port.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export abstract class IOPort<T> extends Port<T> {
103103
}
104104
}
105105

106+
public checkKey(key: symbol | undefined): boolean {
107+
return this._key === key;
108+
}
109+
106110
/**
107111
* Only the holder of the key may obtain a writable port.
108112
* @param key

src/core/reactor.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,10 @@ 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-
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`);
438+
if (this.reactor.canConnect(src, dst) === 2) {
442439
this.reactor._elevatedConnect(src, dst);
440+
} else {
441+
this.reactor._connect(src, dst);
443442
}
444443
} else {
445444
// ERROR
@@ -1096,7 +1095,7 @@ export abstract class Reactor extends Component {
10961095
* @param src The start point of a new connection.
10971096
* @param dst The end point of a new connection.
10981097
*/
1099-
public canConnect<R, S extends R>(src: IOPort<S>, dst: IOPort<R>): boolean {
1098+
public canConnect<R, S extends R>(src: IOPort<S>, dst: IOPort<R>): boolean | number /* dirty hack here */ {
11001099
// Immediate rule out trivial self loops.
11011100
if (src === dst) {
11021101
throw Error("Source port and destination port are the same.");
@@ -1110,6 +1109,11 @@ export abstract class Reactor extends Component {
11101109
throw Error("Destination port is already occupied.");
11111110
}
11121111

1112+
if (! (src.checkKey(this._key) && dst.checkKey(this._key) )) {
1113+
console.log("[debug] Scoping issue. Does not possess valid key for src/dst.")
1114+
return 2;
1115+
}
1116+
11131117
if (!this._runtime.isRunning()) {
11141118
// console.log("Connecting before running")
11151119
// Validate connections between callers and callees.

0 commit comments

Comments
 (0)