Last active
April 29, 2022 10:19
-
-
Save syusui-s/0409b2f6458ed60683865e829aefa000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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