Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Last active April 29, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syusui-s/0409b2f6458ed60683865e829aefa000 to your computer and use it in GitHub Desktop.
Save syusui-s/0409b2f6458ed60683865e829aefa000 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const process = require('process');
const child_process = require('child_process');
const sleep = async ms => new Promise(resolve => setTimeout(resolve, ms));
const file = 'vim.js';
let x = fs.watch(file, (async function fn (t, f) {
console.log(`eventType: ${t}, file: ${f}`)
if ('change' === t)
return;
x.close();
x = null;
for (let i = 0; i < 1000 || x; i++) {
try {
x = fs.watch(file, fn);
x.addListener('close', () => console.log('closed'));
console.log('ok: ' + i);
break;
} catch (e) {
await sleep(50);
}
}
}));
console.log('start watching');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment