sindresorhus/p-wait-for

why we should catch rejection

Closed this issue · 1 comments

why we should catch rejection, but throw nonBooleanError.

i was tring to remove this promise

Promise.resolve().then(condition).then(val => {
, but it fails the test.

I think this code is good enough


	const check = () => {
		const val = condition();

		if (typeof val !== 'boolean') {
			throw new TypeError('Expected condition to return a boolean');
		}

		if (val === true) {
			resolve();
		} else {
			setTimeout(check, interval);
		}
	};