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

Function next

src/cmap/wire_protocol/on_data.ts:53–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51
52 const iterator: AsyncGenerator<Uint8Array> & AsyncDisposable = {
53 next() {
54 // First, we consume all unread events
55 const value = unconsumedEvents.shift();
56 if (value != null) {
57 return Promise.resolve({ value, done: false });
58 }
59
60 // Then we error, if an error happened
61 // This happens one time if at all, because after 'error'
62 // we stop listening
63 if (error != null) {
64 const p = Promise.reject(error);
65 // Only the first element errors
66 error = null;
67 return p;
68 }
69
70 // If the iterator is finished, resolve to done
71 if (finished) return closeHandler();
72
73 // Wait until an event happens
74 const { promise, resolve, reject } = promiseWithResolvers<IteratorResult<Uint8Array>>();
75 unconsumedPromises.push({ resolve, reject });
76 return promise;
77 },
78
79 return() {
80 return closeHandler();

Callers

nothing calls this directly

Calls 5

promiseWithResolversFunction · 0.90
closeHandlerFunction · 0.85
rejectMethod · 0.80
shiftMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected