fix: avoid calling vfs.load multiple times

Massimo Melina committed Dec 14, 2021 at 23:49 UTC 31205f656071e75c257c134cd1311cfd482b1da9
1 file changed +8 -2
src/vfs.ts
+8 -2
@@ -34,8 +34,14 @@ export class Vfs {
34 throw `Couldn't load ${path}`
35 this.root.type = VfsNodeType.root
36 recur(this.root)
37 - if (watchFile)
38 - this.watcher = watch(path, () => this.load(path))
37 + if (!watchFile) return
38 + let doing = false
39 + this.watcher = watch(path, async () => {
40 + if (doing) return
41 + doing = true
42 + await this.load(path)
43 + doing = false
44 + })
45
46 function recur(node:VfsNode) {
47 if (node.type !== VfsNodeType.root && !node.name && node.source)