mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-10 17:53:09 +00:00
23 lines
508 B
TypeScript
23 lines
508 B
TypeScript
|
|
import fs, { promises as asyncFs } from 'fs';
|
||
|
|
import { promisify } from 'util';
|
||
|
|
|
||
|
|
import { delay } from './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);
|
||
|
|
}
|