Skip to content

Commit b9ee91c

Browse files
committed
remove eachAsync
1 parent b923d25 commit b9ee91c

File tree

2 files changed

+0
-72
lines changed

2 files changed

+0
-72
lines changed

src/utils.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -386,46 +386,6 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server
386386
return 0;
387387
}
388388

389-
/**
390-
* Applies the function `eachFn` to each item in `arr`, in parallel.
391-
* @internal
392-
*
393-
* @param arr - An array of items to asynchronously iterate over
394-
* @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.
395-
* @param callback - The callback called after every item has been iterated
396-
*/
397-
export function eachAsync<T = Document>(
398-
arr: T[],
399-
eachFn: (item: T, callback: (err?: AnyError) => void) => void,
400-
callback: Callback
401-
): void {
402-
arr = arr || [];
403-
404-
let idx = 0;
405-
let awaiting = 0;
406-
for (idx = 0; idx < arr.length; ++idx) {
407-
awaiting++;
408-
eachFn(arr[idx], eachCallback);
409-
}
410-
411-
if (awaiting === 0) {
412-
callback();
413-
return;
414-
}
415-
416-
function eachCallback(err?: AnyError) {
417-
awaiting--;
418-
if (err) {
419-
callback(err);
420-
return;
421-
}
422-
423-
if (idx === arr.length && awaiting <= 0) {
424-
callback();
425-
}
426-
}
427-
}
428-
429389
/** @internal */
430390
export function arrayStrictEqual(arr: unknown[], arr2: unknown[]): boolean {
431391
if (!Array.isArray(arr) || !Array.isArray(arr2)) {

test/unit/utils.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
BufferPool,
66
ByteUtils,
77
compareObjectId,
8-
eachAsync,
98
HostAddress,
109
hostMatchesWildcards,
1110
isHello,
@@ -164,37 +163,6 @@ describe('driver utils', function () {
164163
});
165164
});
166165

167-
context('eachAsync()', function () {
168-
it('should callback with an error', function (done) {
169-
eachAsync(
170-
[{ error: false }, { error: true }],
171-
(item, cb) => {
172-
cb(item.error ? new Error('error requested') : undefined);
173-
},
174-
err => {
175-
expect(err).to.exist;
176-
done();
177-
}
178-
);
179-
});
180-
181-
it('should propagate a synchronously thrown error', function (done) {
182-
expect(() =>
183-
eachAsync(
184-
[{}],
185-
() => {
186-
throw new Error('something wicked');
187-
},
188-
err => {
189-
expect(err).to.not.exist;
190-
done(err);
191-
}
192-
)
193-
).to.throw(/something wicked/);
194-
done();
195-
});
196-
});
197-
198166
describe('class BufferPool', function () {
199167
it('should report the correct length', function () {
200168
const buffer = new BufferPool();

0 commit comments

Comments
 (0)