js-waku/src/test_utils/async_fs.ts

23 lines
513 B
TypeScript
Raw Normal View History

import fs, { promises as asyncFs } from 'fs';
import { promisify } from 'util';
import { delay } from '../lib/delay';
export const existsAsync = (filepath: string) =>
asyncFs.access(filepath, fs.constants.F_OK);
export const openAsync = promisify(fs.open);
export const mkdirAsync = asyncFs.mkdir;
export async function waitForFile(path: string) {
let found = false;
do {
try {
await existsAsync(path);
found = true;
} catch (e) {
await delay(500);
}
} while (!found);
}