1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli/js/ops/fs_events): Ignore polling errors caused by return() (#6785)

This commit is contained in:
Nayeem Rahman 2020-07-24 02:33:52 +01:00 committed by GitHub
parent c2507d95f5
commit b61347b255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 5 deletions

View file

@ -2,6 +2,7 @@
((window) => {
const { sendSync, sendAsync } = window.__bootstrap.dispatchJson;
const { errors } = window.__bootstrap.errors;
const { close } = window.__bootstrap.resources;
class FsWatcher {
@ -16,10 +17,17 @@
return this.#rid;
}
next() {
return sendAsync("op_fs_events_poll", {
rid: this.rid,
});
async next() {
try {
return await sendAsync("op_fs_events_poll", {
rid: this.rid,
});
} catch (error) {
if (error instanceof errors.BadResource) {
return { value: undefined, done: true };
}
throw error;
}
}
return(value) {

View file

@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertThrows } from "./test_util.ts";
import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";
// TODO(ry) Add more tests to specify format.
@ -60,3 +60,21 @@ unitTest(
assert(events[1].paths[0].includes(testDir));
},
);
unitTest(
{ perms: { read: true, write: true } },
async function watchFsReturn(): Promise<void> {
const testDir = await Deno.makeTempDir();
const iter = Deno.watchFs(testDir);
// Asynchronously loop events.
const eventsPromise = getTwoEvents(iter);
// Close the watcher.
await iter.return!();
// Expect zero events.
const events = await eventsPromise;
assertEquals(events, []);
},
);