Skip to content

Commit

Permalink
feat(captp): take suggestion in #3289 to prefix questionIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 16, 2021
1 parent 67cc4cb commit a8e0e96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/captp/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ export const makeCapTP = (
const exportedTrapHandlers = new WeakSet();

// Used to construct slot names for promises/non-promises.
// In this verison of CapTP we use strings for export/import slot names.
// In this version of CapTP we use strings for export/import slot names.
// prefixed with 'p' if promises and 'o' otherwise;
let lastPromiseID = 0;
let lastExportID = 0;
// Since we decide the numbers for questions, we use this to increment
// the question key
// Since we decide the ids for questions, we use this to increment the
// question key
let lastQuestionID = 0;

/** @type {Map<number, any>} */
/** @type {Map<string, any>} */
const questions = new Map(); // chosen by us
/** @type {Map<number, any>} */
/** @type {Map<string, any>} */
const answers = new Map(); // chosen by our peer
/** @type {Map<number, any>} */
const imports = new Map(); // chosen by our peer
Expand Down Expand Up @@ -212,11 +212,11 @@ export const makeCapTP = (
* Generate a new question in the questions table and set up a new
* remote handled promise.
*
* @returns {[number, ReturnType<typeof makeRemoteKit>]}
* @returns {[string, ReturnType<typeof makeRemoteKit>]}
*/
const makeQuestion = () => {
lastQuestionID += 1;
const questionID = lastQuestionID;
const questionID = `${ourId}#${lastQuestionID}`;
// eslint-disable-next-line no-use-before-define
const pr = makeRemoteKit(questionID);
questions.set(questionID, pr);
Expand Down
8 changes: 4 additions & 4 deletions packages/captp/test/test-disco.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test('try disconnecting captp', async t => {
);
t.deepEqual(
objs,
[{ type: 'CTP_BOOTSTRAP', questionID: 1, epoch: 0 }],
[{ type: 'CTP_BOOTSTRAP', questionID: 'us#1', epoch: 0 }],
'expected bootstrap messages',
);
ps.push(
Expand All @@ -54,7 +54,7 @@ test('try disconnecting captp', async t => {
t.deepEqual(
objs,
[
{ type: 'CTP_BOOTSTRAP', questionID: 1, epoch: 0 },
{ type: 'CTP_BOOTSTRAP', questionID: 'us#1', epoch: 0 },
{ type: 'CTP_DISCONNECT', reason: undefined, epoch: 0 },
],
'expected clean disconnect',
Expand Down Expand Up @@ -98,7 +98,7 @@ test('try aborting captp with reason', async t => {
);
t.deepEqual(
objs,
[{ type: 'CTP_BOOTSTRAP', questionID: 1, epoch: 0 }],
[{ type: 'CTP_BOOTSTRAP', questionID: 'us#1', epoch: 0 }],
'expected bootstrap messages',
);
ps.push(
Expand All @@ -117,7 +117,7 @@ test('try aborting captp with reason', async t => {
);
t.deepEqual(
objs,
[{ type: 'CTP_BOOTSTRAP', questionID: 1, epoch: 0 }, aborted],
[{ type: 'CTP_BOOTSTRAP', questionID: 'us#1', epoch: 0 }, aborted],
'expected unclean disconnect',
);
await Promise.all(ps);
Expand Down

0 comments on commit a8e0e96

Please sign in to comment.