MCPcopy Create free account
hub / github.com/Effect-TS/effect / watchNode

Function watchNode

packages/platform/node-shared/src/NodeFileSystem.ts:553–596  ·  view source on GitHub ↗
(path: string, options?: FileSystem.WatchOptions)

Source from the content-addressed store, hash-verified

551// == watch
552
553const watchNode = (path: string, options?: FileSystem.WatchOptions) =>
554 Stream.callback<FileSystem.WatchEvent, Error.PlatformError>((queue) =>
555 Effect.acquireRelease(
556 Effect.sync(() => {
557 const watcher = NFS.watch(path, {
558 recursive: options?.recursive ?? false
559 }, (event, path) => {
560 if (!path) return
561 switch (event) {
562 case "rename": {
563 Effect.runFork(Effect.matchEffect(stat(path), {
564 onSuccess: (_) => Queue.offer(queue, { _tag: "Create", path }),
565 onFailure: (_) => Queue.offer(queue, { _tag: "Remove", path })
566 }))
567 return
568 }
569 case "change": {
570 Queue.offerUnsafe(queue, { _tag: "Update", path })
571 return
572 }
573 }
574 })
575 watcher.on("error", (error) => {
576 Queue.failCauseUnsafe(
577 queue,
578 Cause.fail(
579 Error.systemError({
580 module: "FileSystem",
581 _tag: "Unknown",
582 method: "watch",
583 pathOrDescriptor: path,
584 cause: error
585 })
586 )
587 )
588 })
589 watcher.on("close", () => {
590 Queue.endUnsafe(queue)
591 })
592 return watcher
593 }),
594 (watcher) => Effect.sync(() => watcher.close())
595 )
596 )
597
598const watch = (
599 backend: Option.Option<FileSystem.WatchBackend["Service"]>,

Callers 1

watchFunction · 0.85

Calls 7

offerMethod · 0.80
offerUnsafeMethod · 0.80
onMethod · 0.65
closeMethod · 0.65
statFunction · 0.50
syncMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected