diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-03-20 11:19:53 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-20 11:19:53 +0530 |
commit | 5b2f689f085fea8ff52f296c94072a1fb29dd054 (patch) | |
tree | d62a9b77c76055f68e96392f16ddb84820f198ac /runtime/js/40_fs_events.js | |
parent | 737adbe1b076cda299131704520e9fe2d41b7611 (diff) |
fix(ext/node): FsWatcher ref and unref (#22987)
Fixes https://github.com/denoland/deno/issues/22973
---------
Co-authored-by: Satya Rohith <me@satyarohith.com>
Diffstat (limited to 'runtime/js/40_fs_events.js')
-rw-r--r-- | runtime/js/40_fs_events.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js index 9592b9f7d..3493ddcd9 100644 --- a/runtime/js/40_fs_events.js +++ b/runtime/js/40_fs_events.js @@ -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)) { |