* Wait for a specific event (Promise-based).
(
eventType: T,
options?: GitEventSubscriptionOptions & { timeout?: number }
)
| 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 |
no test coverage detected