Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove ambient authority from batched-deliver.js
Browse files Browse the repository at this point in the history
turadg committed Jan 23, 2023

Verified

This commit was signed with the committer’s verified signature.
turadg Turadg Aleahmad
1 parent 39e8c40 commit 49d9b11
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/cosmic-swingset/src/sim-chain.js
Original file line number Diff line number Diff line change
@@ -220,5 +220,9 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
});

const batchDelayMs = delay ? delay * 1000 : undefined;
return makeBatchedDeliver(deliver, batchDelayMs);
return makeBatchedDeliver(
deliver,
{ clearTimeout, setTimeout },
batchDelayMs,
);
}
15 changes: 14 additions & 1 deletion packages/internal/src/batched-deliver.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/* global setTimeout clearTimeout */
export const DEFAULT_BATCH_TIMEOUT_MS = 1000;

/**
* @typedef {(message: any[], ackNum: number) => void} DeliverMessages
*/

/**
*
* @param {DeliverMessages} deliver
* @param {{ clearTimeout: NodeJS.clearTimeout, setTimeout: NodeJS.setTimeout }} io
* @param {number} batchTimeoutMs
*/
export function makeBatchedDeliver(
deliver,
{ clearTimeout, setTimeout },
batchTimeoutMs = DEFAULT_BATCH_TIMEOUT_MS,
) {
let batchedMessages = [];
let latestAckNum = 0;
let deliverTimeout;

/**
* @type {DeliverMessages}
*/
async function batchedDeliver(newMessages, ackNum) {
// If we have no existing messages, reset the deliver timeout.
//
8 changes: 6 additions & 2 deletions packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global setTimeout Buffer */
/* global clearTimeout setTimeout Buffer */
import path from 'path';
import fs from 'fs';
import url from 'url';
@@ -806,5 +806,9 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(

// Now that we've started consuming blocks, tell our caller how to deliver
// messages.
return makeBatchedDeliver(deliver, Math.min(DEFAULT_BATCH_TIMEOUT_MS, 2000));
return makeBatchedDeliver(
deliver,
{ clearTimeout, setTimeout },
Math.min(DEFAULT_BATCH_TIMEOUT_MS, 2000),
);
}

0 comments on commit 49d9b11

Please sign in to comment.