-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(slot): prevent crosstalk by tracking inbound vs. outbound slots
- Loading branch information
1 parent
98ea387
commit 19906c4
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test } from 'tape-promise/tape'; | ||
import { harden, makeCapTP, E } from '../lib/captp'; | ||
|
||
test('prevent crosstalk', async t => { | ||
try { | ||
const debug = false; | ||
let rightDispatch; | ||
const { dispatch: leftDispatch, getBootstrap: leftBootstrap } = makeCapTP( | ||
'left', | ||
obj => { | ||
if (debug) { | ||
console.log('toRight', obj); | ||
} | ||
rightDispatch(obj); | ||
}, | ||
); | ||
({ dispatch: rightDispatch } = makeCapTP( | ||
'right', | ||
obj => { | ||
if (debug) { | ||
console.log('toLeft', obj); | ||
} | ||
leftDispatch(obj); | ||
}, | ||
harden({ | ||
isSide(objP, side) { | ||
return E(objP).side().then(s => t.equal(s, side, `obj.side() is ${side}`)); | ||
}, | ||
side() { | ||
return 'right'; | ||
}, | ||
}) | ||
)); | ||
const rightRef = leftBootstrap(); | ||
|
||
await E(rightRef).isSide(rightRef, 'right'); | ||
const leftRef = harden({ | ||
side() { | ||
return 'left'; | ||
}, | ||
}); | ||
await E(rightRef).isSide(leftRef, 'left'); | ||
} catch (e) { | ||
t.isNot(e, e, 'unexpected exception'); | ||
} finally { | ||
t.end(); | ||
} | ||
}); |