async function waitFor(fn, timeout = 2000) {
	const start = Date.now();

	while (start + timeout >= Date.now()) {
		try {
			const result = await fn();
			if (result) return true;
		} catch (err) {
			if (!ignoreError(err)) {
				throw err;
			}
		}

		// Wait a little before the next iteration
		await wait(10);
	}

	return false;
}
@param {() => boolean | Promise<boolean>} fn
@param {number} timeout
@returns {Promise<boolean>}