Skip to content

Commit 1dff95e

Browse files
committed
chore: cleaning up promise variable names
1 parent bb8a180 commit 1dff95e

File tree

7 files changed

+33
-27
lines changed

7 files changed

+33
-27
lines changed

src/PolykeyAgent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class PolykeyAgent {
806806
if (nodeId == null) {
807807
utils.never(`failed to decode NodeId "${nodeIdEncoded}"`);
808808
}
809-
const setNodeProm = this.nodeManager.setNode(
809+
const setNodeP = this.nodeManager.setNode(
810810
nodeId,
811811
optionsDefaulted.seedNodes[nodeIdEncoded],
812812
{
@@ -816,7 +816,7 @@ class PolykeyAgent {
816816
},
817817
true,
818818
);
819-
setNodeProms.push(setNodeProm);
819+
setNodeProms.push(setNodeP);
820820
}
821821
await Promise.all(setNodeProms);
822822
await this.nodeGraph.start({ fresh });

src/audit/Audit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Audit {
177177
promise.cancel(new auditErrors.ErrorAuditNotRunning());
178178
}
179179
}
180-
await Promise.all([...this.taskPromises]).catch(() => {});
180+
await Promise.allSettled([...this.taskPromises]);
181181
this.logger.info(`Stopped ${this.constructor.name}`);
182182
}
183183

@@ -333,6 +333,7 @@ class Audit {
333333
resolveBlockP = resolveP;
334334
blockPSignal = signal;
335335
});
336+
void blockP.catch(() => {});
336337
this.taskPromises.add(blockP);
337338

338339
const iterator = this.getAuditEvents(topicPath, {

src/identities/IdentitiesManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ class IdentitiesManager {
265265
);
266266
}
267267
// Create identity claim on our node
268-
const publishedClaimProm = promise<IdentitySignedClaim>();
268+
const { p: publishedClaimP, resolveP: publishedClaimResolveP } =
269+
promise<IdentitySignedClaim>();
269270
await this.db.withTransactionF((tran) =>
270271
this.sigchain.addClaim(
271272
{
@@ -281,7 +282,7 @@ class IdentitiesManager {
281282
identityId,
282283
claim,
283284
);
284-
publishedClaimProm.resolveP(identitySignedClaim);
285+
publishedClaimResolveP(identitySignedClaim);
285286
// Append the ProviderIdentityClaimId to the token
286287
const payload: ClaimLinkIdentity = {
287288
...claim.payload,
@@ -294,7 +295,7 @@ class IdentitiesManager {
294295
tran,
295296
),
296297
);
297-
const publishedClaim = await publishedClaimProm.p;
298+
const publishedClaim = await publishedClaimP;
298299
// Publish claim on identity
299300
const issNodeInfo = {
300301
nodeId: this.keyRing.getNodeId(),

src/nodes/NodeConnectionManager.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -571,25 +571,25 @@ class NodeConnectionManager {
571571
);
572572
this.quicSocket.removeEventListener(EventAll.name, this.handleEventAll);
573573

574-
const destroyProms: Array<Promise<void>> = [];
574+
const destroyPs: Array<Promise<void>> = [];
575575
for (const [nodeId] of this.connections) {
576576
// It exists so we want to destroy it
577-
const destroyProm = this.destroyConnection(
577+
const destroyP = this.destroyConnection(
578578
IdInternal.fromString<NodeId>(nodeId),
579579
force,
580580
);
581-
destroyProms.push(destroyProm);
581+
destroyPs.push(destroyP);
582582
}
583-
await Promise.all(destroyProms);
584-
const signallingProms: Array<PromiseCancellable<void> | Promise<void>> = [];
583+
await Promise.all(destroyPs);
584+
const signallingPs: Array<PromiseCancellable<void> | Promise<void>> = [];
585585
for (const [, activePunch] of this.activeHolePunchPs) {
586-
signallingProms.push(activePunch);
586+
signallingPs.push(activePunch);
587587
activePunch.cancel();
588588
}
589589
for (const activeSignal of this.activeSignalFinalPs) {
590-
signallingProms.push(activeSignal);
590+
signallingPs.push(activeSignal);
591591
}
592-
await Promise.allSettled(signallingProms);
592+
await Promise.allSettled(signallingPs);
593593
await this.quicServer.stop({ force: true });
594594
await this.quicSocket.stop({ force: true });
595595
await this.rpcServer.stop({ force: true });
@@ -1113,13 +1113,13 @@ class NodeConnectionManager {
11131113
): Promise<void> {
11141114
// We need to send a random data packet to the target until the process times out or a connection is established
11151115
let ended = false;
1116-
const endedProm = utils.promise();
1116+
const { p: endedP, resolveP: endedResolveP } = utils.promise();
11171117
if (ctx.signal.aborted) {
1118-
endedProm.resolveP();
1118+
endedResolveP();
11191119
}
11201120
const onAbort = () => {
11211121
ended = true;
1122-
endedProm.resolveP();
1122+
endedResolveP();
11231123
ctx.signal.removeEventListener('abort', onAbort);
11241124
};
11251125
ctx.signal.addEventListener('abort', onAbort);
@@ -1134,7 +1134,7 @@ class NodeConnectionManager {
11341134
await this.quicSocket
11351135
.send(Buffer.from(message), port, host)
11361136
.catch(() => {});
1137-
await Promise.race([utils.sleep(delay), endedProm.p]);
1137+
await Promise.race([utils.sleep(delay), endedP]);
11381138
if (ended) break;
11391139
delay *= 2;
11401140
}

src/nodes/NodeConnectionQueue.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export class NodeConnectionQueue {
189189
ctx: ContextCancellable,
190190
): Promise<void> {
191191
const abortP = utils.signalPromise(ctx.signal);
192+
void abortP.catch(() => {});
192193
try {
193194
while (
194195
!this.connectionMade &&

src/nodes/NodeManager.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ class NodeManager {
290290
const task = await this.updateRefreshBucketDelay(i, 0, false);
291291
refreshBuckets.push(task.promise());
292292
}
293-
const signalProm = utils.signalPromise(ctx.signal);
294-
await Promise.race([Promise.all(refreshBuckets), signalProm]).finally(
293+
const signalP = utils.signalPromise(ctx.signal);
294+
await Promise.race([Promise.all(refreshBuckets), signalP]).finally(
295295
async () => {
296296
// Clean up signal promise when done
297-
signalProm.cancel();
298-
await signalProm;
297+
signalP.cancel();
298+
await signalP;
299299
},
300300
);
301301
};
@@ -1424,8 +1424,9 @@ class NodeManager {
14241424
};
14251425

14261426
// Now we want to send our own claim signed
1427-
const halfSignedClaimProm = utils.promise<SignedTokenEncoded>();
1428-
const claimProm = this.sigchain.addClaim(
1427+
const { p: halfSignedClaimP, resolveP: halfSignedClaimResolveP } =
1428+
utils.promise<SignedTokenEncoded>();
1429+
const claimP = this.sigchain.addClaim(
14291430
{
14301431
typ: 'ClaimLinkNode',
14311432
iss: nodesUtils.encodeNodeId(requestingNodeId),
@@ -1436,7 +1437,7 @@ class NodeManager {
14361437
const halfSignedClaim = token.toSigned();
14371438
const halfSignedClaimEncoded =
14381439
claimsUtils.generateSignedClaim(halfSignedClaim);
1439-
halfSignedClaimProm.resolveP(halfSignedClaimEncoded);
1440+
halfSignedClaimResolveP(halfSignedClaimEncoded);
14401441
const readStatus = await input.next();
14411442
if (readStatus.done) {
14421443
throw new claimsErrors.ErrorEmptyStream();
@@ -1462,10 +1463,11 @@ class NodeManager {
14621463
return fullySignedToken;
14631464
},
14641465
);
1466+
void claimP.catch(() => {});
14651467
yield {
1466-
signedTokenEncoded: await halfSignedClaimProm.p,
1468+
signedTokenEncoded: await halfSignedClaimP,
14671469
};
1468-
const [, claim] = await claimProm;
1470+
const [, claim] = await claimP;
14691471
// With the claim created we want to add it to the gestalt graph
14701472
const issNodeInfo = {
14711473
nodeId: requestingNodeId,

src/nodes/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ function generateRandomNodeIdForBucket(
314314
* This is generally used to check the connection has failed
315315
* before cleaning it up.
316316
*/
317+
// FIXME: need to include ErrorQUICConnectionIdleTimeout error in this list.
317318
function isConnectionError(e): boolean {
318319
return (
319320
e instanceof nodesErrors.ErrorNodeConnectionDestroyed ||

0 commit comments

Comments
 (0)