All files / packages/utils/src promise.ts

60% Statements 6/10
100% Branches 0/0
50% Functions 3/6
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26332x             332x           78x 78x   78x 78x                
export const wait = (ms: number) =>
	new Promise((resolve) => {
		setTimeout(resolve, ms);
	});
 
type Unsubscribe = () => void;
 
export const promisifyEvent = <T = void>(
	subscribe: (
		listener: (result: T) => void,
		errorListener: (error: Error) => void,
	) => Unsubscribe | void,
) =>
	new Promise<T>((resolve, reject) => {
		const unsubscribe = subscribe(
			(result) => {
				unsubscribe?.();
				resolve(result);
			},
			(error) => {
				unsubscribe?.();
				reject(error);
			},
		);
	});