<commit_before>export const resolvedPromise = Promise.resolve(true);

export async function waitFor<T>(action: () => T, checkEveryMilliseconds: number = 500, tryForMilliseconds: number = 10000, token?: { isCancellationRequested: boolean }): Promise<T | undefined> {
	let timeRemaining = tryForMilliseconds;
	while (timeRemaining > 0 && !(token && token.isCancellationRequested)) {
		const res = action();
		if (res)
			return res;
		await new Promise((resolve) => setTimeout(resolve, checkEveryMilliseconds));
		timeRemaining -= checkEveryMilliseconds;
	}
}
<commit_msg>Fix race conditions in tests by fixing support for promises in waitFor<commit_after>export const resolvedPromise = Promise.resolve(true);

export async function waitFor<T>(action: () => T | Promise<T>, checkEveryMilliseconds: number = 500, tryForMilliseconds: number = 10000, token?: { isCancellationRequested: boolean }): Promise<T | undefined> {
	let timeRemaining = tryForMilliseconds;
	while (timeRemaining > 0 && !(token && token.isCancellationRequested)) {
		const res = await action();
		if (res)
			return res;
		await new Promise((resolve) => setTimeout(resolve, checkEveryMilliseconds));
		timeRemaining -= checkEveryMilliseconds;
	}
}

{'fraction_non_alphanumeric': 0.11759868421052631, 'fraction_numerical': 0.014802631578947368, 'mean_word_length': 6.034682080924855, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4200627', 'n_tokens_mistral': 370, 'n_tokens_neox': 345, 'n_words': 97}