Skip to content

Commit 9863ea3

Browse files
1 parent bd9da49 commit 9863ea3

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/pathwatcher-rx.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ import 'rxjs/add/operator/publish';
77

88
export function watchPathDirect(directory) {
99
return Observable.create((subj) => {
10+
let watcher = null;
1011
let dead = false;
1112

12-
const watcher = fs.watch(directory, {}, (eventType, fileName) => {
13-
if (dead) return;
14-
subj.next({eventType, fileName});
15-
});
13+
try {
14+
watcher = fs.watch(directory, {}, (eventType, fileName) => {
15+
if (dead) return;
16+
subj.next({eventType, fileName});
17+
});
1618

17-
watcher.on('error', (e) => {
19+
watcher.on('error', (e) => {
20+
dead = true;
21+
subj.error(e);
22+
});
23+
} catch (e) {
1824
dead = true;
19-
subj.error(e);
20-
});
21-
22-
return new Subscription(() => { if (!dead) { watcher.close(); } });
25+
if (e.code === "ENOENT") {
26+
// that's ok, we just won't watch the non-existent directory
27+
} else {
28+
// if it's not that, let's log and continue
29+
console.warn(e.message);
30+
}
31+
}
32+
return new Subscription(() => { if (!dead && watcher) { watcher.close(); } });
2333
});
2434
}
2535

0 commit comments

Comments
 (0)