export const pWhile = async ( condition: (value: T | undefined) => boolean, action: () => T | PromiseLike ): Promise => { const loop = async (actionResult: T | undefined): Promise => { if (condition(actionResult)) { return loop(await action()) } } return loop(undefined) }