MCPcopy
hub / github.com/microsoft/vscode / poll

Method poll

test/automation/src/code.ts:353–387  ·  view source on GitHub ↗
(
		fn: () => Promise<T>,
		acceptFn: (result: T) => boolean,
		timeoutMessage: string,
		retryCount = 200,
		retryInterval = 100 // millis
	)

Source from the content-addressed store, hash-verified

351 }
352
353 private async poll<T>(
354 fn: () => Promise<T>,
355 acceptFn: (result: T) => boolean,
356 timeoutMessage: string,
357 retryCount = 200,
358 retryInterval = 100 // millis
359 ): Promise<T> {
360 let trial = 1;
361 let lastError: string = '';
362
363 while (true) {
364 if (trial > retryCount) {
365 this.logger.log('Timeout!');
366 this.logger.log(lastError);
367 this.logger.log(`Timeout: ${timeoutMessage} after ${(retryCount * retryInterval) / 1000} seconds.`);
368
369 throw new Error(`Timeout: ${timeoutMessage} after ${(retryCount * retryInterval) / 1000} seconds.`);
370 }
371
372 let result;
373 try {
374 result = await fn();
375 if (acceptFn(result)) {
376 return result;
377 } else {
378 lastError = 'Did not pass accept function';
379 }
380 } catch (e: any) {
381 lastError = Array.isArray(e.stack) ? e.stack.join(os.EOL) : e.stack;
382 }
383
384 await this.wait(retryInterval);
385 trial++;
386 }
387 }
388}
389
390export function findElement(element: IElement, fn: (element: IElement) => boolean): IElement | null {

Callers 11

waitForTextContentMethod · 0.95
waitAndClickMethod · 0.95
waitForSetValueMethod · 0.95
waitForElementsMethod · 0.95
waitForActiveElementMethod · 0.95
waitForTitleMethod · 0.95
waitForTypeInEditorMethod · 0.95
waitForTerminalBufferMethod · 0.95
writeInTerminalMethod · 0.95
whenWorkbenchRestoredMethod · 0.95

Calls 5

waitMethod · 0.95
isArrayMethod · 0.80
logMethod · 0.65
joinMethod · 0.65
fnFunction · 0.50

Tested by

no test coverage detected