fix(ext/node): FsWatcher ref and unref (#22987)

Fixes https://github.com/denoland/deno/issues/22973

---------

Co-authored-by: Satya Rohith <me@satyarohith.com>
This commit is contained in:
Divy Srivastava 2024-03-20 11:19:53 +05:30 committed by GitHub
parent 737adbe1b0
commit 5b2f689f08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 7 deletions

View file

@ -17,6 +17,7 @@ import { SymbolDispose } from "ext:deno_web/00_infra.js";
class FsWatcher {
#rid = 0;
#promise;
constructor(paths, options) {
const { recursive } = options;
@ -32,9 +33,18 @@ class FsWatcher {
return this.#rid;
}
unref() {
core.unrefOpPromise(this.#promise);
}
ref() {
core.refOpPromise(this.#promise);
}
async next() {
try {
const value = await op_fs_events_poll(this.#rid);
this.#promise = op_fs_events_poll(this.#rid);
const value = await this.#promise;
return value ? { value, done: false } : { value: undefined, done: true };
} catch (error) {
if (ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error)) {