@@ -34,6 +34,7 @@ const uuid = require('uuid/v1');
3434const mime = require('mime');
3535const path = require('path');
3636const vfs = require('./vfs');
37+ const {closeWatches} = require('./utils/core.js');
3738const consola = require('consola');
3839const logger = consola.withTag('Filesystem');
3940
@@ -62,12 +63,12 @@ class Filesystem {
6263 /**
6364 * Destroys instance
6465 */
65- destroy() {
66- this.watches.forEach (({watch}) => {
67- if ( watch && typeof watch.close === 'function') {
68- watch.close( );
69- }
70- } );
66+ async destroy() {
67+ const watches = this.watches.filter (({watch}) => {
68+ return watch && typeof watch.close === 'function';
69+ }).map(({watch}) => watch);
70+
71+ await closeWatches(watches );
7172
7273 this.watches = [];
7374 }
@@ -204,13 +205,13 @@ class Filesystem {
204205 /**
205206 * Unmounts given mountpoint
206207 * @param {object} mount Mountpoint
207- * @return {boolean}
208+ * @return {Promise< boolean> }
208209 */
209- unmount(mountpoint) {
210+ async unmount(mountpoint) {
210211 const found = this.watches.find(w => w.id === mountpoint.id);
211212
212213 if (found && found.watch) {
213- found.watch.close();
214+ await found.watch.close();
214215 }
215216
216217 const index = this.mountpoints.indexOf(mountpoint);
@@ -271,6 +272,8 @@ class Filesystem {
271272 }, args], filter);
272273 });
273274
275+ watch.on('error', error => logger.warn('Mountpoint watch error', error));
276+
274277 this.watches.push({
275278 id: mountpoint.id,
276279 watch
0 commit comments