MCPcopy Create free account
hub / github.com/GCWing/BitFun / waitFor

Method waitFor

src/web-ui/src/infrastructure/event-bus/EventBus.ts:174–191  ·  view source on GitHub ↗

* Wait for the next occurrence of an event.

(event: string, timeout?: number)

Source from the content-addressed store, hash-verified

172 * Wait for the next occurrence of an event.
173 */
174 async waitFor<T = any>(event: string, timeout?: number): Promise<T> {
175 return new Promise((resolve, reject) => {
176 const timeoutMs = timeout ?? this.options.timeout;
177 let timeoutId: ReturnType<typeof setTimeout> | null = null;
178
179 const cleanup = this.once(event, (data: T) => {
180 if (timeoutId) {
181 clearTimeout(timeoutId);
182 }
183 resolve(data);
184 });
185
186 timeoutId = setTimeout(() => {
187 cleanup();
188 reject(new Error(`Timeout waiting for event '${event}' after ${timeoutMs}ms`));
189 }, timeoutMs);
190 });
191 }
192
193 /**
194 * Remove listeners.

Calls 4

onceMethod · 0.95
rejectFunction · 0.85
resolveFunction · 0.50
cleanupFunction · 0.50

Tested by

no test coverage detected