Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node:fs/promises watcher polyfill is not AsyncIterable #23562

Open
jldec opened this issue Apr 25, 2024 · 0 comments
Open

node:fs/promises watcher polyfill is not AsyncIterable #23562

jldec opened this issue Apr 25, 2024 · 0 comments

Comments

@jldec
Copy link

jldec commented Apr 25, 2024

Version: Deno 1.42.4

The deno polyfill for node fsPromises.watch() does not appear to return an AsyncIterator as documented here for node.

With deno run, using the returned watcher with for await throws TypeError: watcher is not async iterable.
The same code works with node.

$ deno run fswatch-node.js
✅ Granted read access to <CWD>.
Watching for file changes in /Users/jldec/opral/deno, press Ctrl+C to exit.
error: Uncaught (in promise) TypeError: watcher is not async iterable
  for await (const event of watcher) {
                            ^
    at run (file:///Users/jldec/opral/deno/fswatch-node.js:8:29)
    at file:///Users/jldec/opral/deno/fswatch-node.js:13:1
    
$ node fswatch-node.js 
Watching for file changes in /Users/jldec/opral/deno-node-fs-promises-watch, press Ctrl+C to exit.
>>>> event { eventType: 'rename', filename: 'foo.bar' }

repro

fswatch-node.js from: https://github.com/jldec/deno-node-fs-promises-watch

import process from "node:process"
import fs from "node:fs/promises"

async function run() {
  const watcher = fs.watch(process.cwd(), { recursive: true })
  console.log(`Watching for file changes in ${process.cwd()}, press Ctrl+C to exit.`);

  for await (const event of watcher) {
    console.log(">>>> event", event)
  }
}

run()

Ref: https://github.com/denoland/deno/blob/main/ext/node/polyfills/_fs/_fs_watch.ts#L126C5-L126C18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant