MCPcopy
hub / github.com/mongodb/node-mongodb-native / once

Function once

src/utils.ts:1281–1300  ·  view source on GitHub ↗
(ee: EventEmitter, name: string, options?: Abortable)

Source from the content-addressed store, hash-verified

1279 * @param name - An event name to wait for
1280 */
1281export async function once<T>(ee: EventEmitter, name: string, options?: Abortable): Promise<T> {
1282 options?.signal?.throwIfAborted();
1283
1284 const { promise, resolve, reject } = promiseWithResolvers<T>();
1285 const onEvent = (data: T) => resolve(data);
1286 const onError = (error: Error) => reject(error);
1287 const abortListener = addAbortListener(options?.signal, function () {
1288 reject(this.reason);
1289 });
1290
1291 ee.once(name, onEvent).once('error', onError);
1292
1293 try {
1294 return await promise;
1295 } finally {
1296 ee.off(name, onEvent);
1297 ee.off('error', onError);
1298 abortListener?.[kDispose]();
1299 }
1300}
1301
1302export function maybeAddIdToDocuments(
1303 collection: Collection,

Callers 15

writeCommandMethod · 0.90
itInNodeProcessFunction · 0.85
gridfs.test.tsFile · 0.85
testFunction · 0.85
testFunction · 0.85
initIteratorModeFunction · 0.85
initIteratorModeFunction · 0.85

Calls 5

promiseWithResolversFunction · 0.85
addAbortListenerFunction · 0.85
throwIfAbortedMethod · 0.80
onceMethod · 0.80
offMethod · 0.80

Tested by 9

testFunction · 0.68
testFunction · 0.68
initIteratorModeFunction · 0.68
initIteratorModeFunction · 0.68
testFunction · 0.68
useBigInt64FalseTestFunction · 0.68
testFunction · 0.68
runFunction · 0.68
runSrvPollerTestFunction · 0.68