【问题标题】:How to unwatch in Deno?如何在 Deno 中取消观看?
【发布时间】:2020-07-18 23:55:51
【问题描述】:

有一个Deno.watch api 用于监视文件系统事件:

const watcher = Deno.watchFs("/");
for await (const event of watcher) {
   console.log(">>>> event", event);
   // { kind: "create", paths: [ "/foo.txt" ] }
}

但是在调用Deno.watch 之后如何unwatch?

【问题讨论】:

    标签: deno


    【解决方案1】:

    您可以拨打watcher.return

    const watcher = Deno.watchFs("/your-dir");
    
    setTimeout(() => {
      watcher.return();
    }, 2000)
    
    for await (const event of watcher) {
       console.log(">>>> event", event);
       // { kind: "create", paths: [ "/foo.txt" ] }
    }
    

    不建议观看整个文件系统/,这将需要很长时间才能启动。 Deno.watchFs 同步调用op_fs_events_open。获取watcher 后,操作是异步的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多