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

Method waitFor

src/web-ui/src/tools/git/services/GitEventService.ts:156–183  ·  view source on GitHub ↗

* Wait for a specific event (Promise-based).

(
    eventType: T,
    options?: GitEventSubscriptionOptions & { timeout?: number }
  )

Source from the content-addressed store, hash-verified

154 * Wait for a specific event (Promise-based).
155 */
156 waitFor<T extends GitEventType>(
157 eventType: T,
158 options?: GitEventSubscriptionOptions & { timeout?: number }
159 ): Promise<Extract<GitEvent, { type: T }>> {
160 return new Promise((resolve, reject) => {
161 const timeout = options?.timeout || 10000;
162
163 let unsubscriber: () => void = () => {};
164 let timeoutId: ReturnType<typeof setTimeout> | null = null;
165
166 const cleanup = () => {
167 if (timeoutId) clearTimeout(timeoutId);
168 if (unsubscriber) unsubscriber();
169 };
170
171
172 timeoutId = setTimeout(() => {
173 cleanup();
174 reject(new Error(`Timed out waiting for Git event ${eventType}`));
175 }, timeout);
176
177
178 unsubscriber = this.once(eventType, (event) => {
179 cleanup();
180 resolve(event);
181 });
182 });
183 }
184}
185
186

Calls 4

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

Tested by

no test coverage detected