From b9ee91c03f4114b538d4a70b8dbe46cd9823c5a3 Mon Sep 17 00:00:00 2001 From: Warren James Date: Fri, 8 Mar 2024 14:32:14 -0500 Subject: [PATCH] remove eachAsync --- src/utils.ts | 40 ---------------------------------------- test/unit/utils.test.ts | 32 -------------------------------- 2 files changed, 72 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 4a6f7a4e8c..98e3950fcb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -386,46 +386,6 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server return 0; } -/** - * Applies the function `eachFn` to each item in `arr`, in parallel. - * @internal - * - * @param arr - An array of items to asynchronously iterate over - * @param eachFn - A function to call on each item of the array. The callback signature is `(item, callback)`, where the callback indicates iteration is complete. - * @param callback - The callback called after every item has been iterated - */ -export function eachAsync( - arr: T[], - eachFn: (item: T, callback: (err?: AnyError) => void) => void, - callback: Callback -): void { - arr = arr || []; - - let idx = 0; - let awaiting = 0; - for (idx = 0; idx < arr.length; ++idx) { - awaiting++; - eachFn(arr[idx], eachCallback); - } - - if (awaiting === 0) { - callback(); - return; - } - - function eachCallback(err?: AnyError) { - awaiting--; - if (err) { - callback(err); - return; - } - - if (idx === arr.length && awaiting <= 0) { - callback(); - } - } -} - /** @internal */ export function arrayStrictEqual(arr: unknown[], arr2: unknown[]): boolean { if (!Array.isArray(arr) || !Array.isArray(arr2)) { diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index b5fcadbffc..8cb338c516 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -5,7 +5,6 @@ import { BufferPool, ByteUtils, compareObjectId, - eachAsync, HostAddress, hostMatchesWildcards, isHello, @@ -164,37 +163,6 @@ describe('driver utils', function () { }); }); - context('eachAsync()', function () { - it('should callback with an error', function (done) { - eachAsync( - [{ error: false }, { error: true }], - (item, cb) => { - cb(item.error ? new Error('error requested') : undefined); - }, - err => { - expect(err).to.exist; - done(); - } - ); - }); - - it('should propagate a synchronously thrown error', function (done) { - expect(() => - eachAsync( - [{}], - () => { - throw new Error('something wicked'); - }, - err => { - expect(err).to.not.exist; - done(err); - } - ) - ).to.throw(/something wicked/); - done(); - }); - }); - describe('class BufferPool', function () { it('should report the correct length', function () { const buffer = new BufferPool();