export async function asyncWhile( checker: (index: number) => boolean | Promise, callback: (index: number) => void | Promise ) { let index = 0; const newCallback = async () => { const checkRes = await checker(index); if (checkRes) { await callback(index); index++; await newCallback(); } }; return await newCallback(); } export async function asyncForEach( array: T[], callback: (item: T, index: number) => boolean | Promise ) { let index = 0; const newCallback = async () => { const item = array[index]; const res = await callback(item, index); if (index < array.length - 1 && res !== false) { index++; await newCallback(); } }; return await newCallback(); } export function nextTick(time = 0) { return new Promise((resolve) => { setTimeout(() => { resolve(true); }, time); }); } export function objectForEach>( obj: O, callback: (value: O[keyof O], key: PropertyKey) => void ) { const keys = Reflect.ownKeys(obj); keys.forEach((key) => { callback(Reflect.get(obj, key), key); }); } export async function asyncObjectForEach< O extends Record >( obj: O, callback: (value: O[keyof O], key: PropertyKey) => boolean | Promise ) { const keys = Reflect.ownKeys(obj); let index = 0; const newCallback = async () => { const key = keys[index]; const res = await callback(Reflect.get(obj, key), key); if (index < keys.length - 1 && res !== false) { index++; await newCallback(); } }; return await newCallback(); }