MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / drain

Function drain

packages/core/src/utils/promisebuffer.ts:69–87  ·  view source on GitHub ↗

* Wait for all promises in the queue to resolve or for timeout to expire, whichever comes first. * * @param timeout The time, in ms, after which to resolve to `false` if the queue is still non-empty. Passing `0` (or * not passing anything) will make the promise wait as long as it takes for

(timeout?: number)

Source from the content-addressed store, hash-verified

67 * `false` otherwise
68 */
69 function drain(timeout?: number): PromiseLike<boolean> {
70 if (!buffer.size) {
71 return resolvedSyncPromise(true);
72 }
73
74 // We want to resolve even if one of the promises rejects
75 const drainPromise = Promise.allSettled(Array.from(buffer)).then(() => true);
76
77 if (!timeout) {
78 return drainPromise;
79 }
80
81 const promises = [
82 drainPromise,
83 new Promise<boolean>(resolve => safeUnref(setTimeout(() => resolve(false), timeout))),
84 ];
85
86 return Promise.race(promises);
87 }
88
89 return {
90 get $(): PromiseLike<T>[] {

Callers

nothing calls this directly

Calls 6

resolvedSyncPromiseFunction · 0.90
safeUnrefFunction · 0.90
setTimeoutFunction · 0.85
resolveFunction · 0.70
thenMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected