Skip to content

Commit

Permalink
remove eachAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Mar 8, 2024
1 parent b923d25 commit b9ee91c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 72 deletions.
40 changes: 0 additions & 40 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = Document>(
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)) {
Expand Down
32 changes: 0 additions & 32 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
BufferPool,
ByteUtils,
compareObjectId,
eachAsync,
HostAddress,
hostMatchesWildcards,
isHello,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b9ee91c

Please sign in to comment.