MCPcopy
hub / github.com/Effect-TS/effect / watchNode

Function watchNode

packages/platform-node-shared/src/internal/fileSystem.ts:538–579  ·  view source on GitHub ↗
(path: string, options?: FileSystem.WatchOptions)

Source from the content-addressed store, hash-verified

536// == watch
537
538const watchNode = (path: string, options?: FileSystem.WatchOptions) =>
539 Stream.asyncScoped<FileSystem.WatchEvent, Error.PlatformError>((emit) =>
540 Effect.acquireRelease(
541 Effect.sync(() => {
542 const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
543 if (!path) return
544 switch (event) {
545 case "rename": {
546 emit.fromEffect(Effect.matchEffect(stat(path), {
547 onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path })),
548 onFailure: (err) =>
549 err._tag === "SystemError" && err.reason === "NotFound"
550 ? Effect.succeed(FileSystem.WatchEventRemove({ path }))
551 : Effect.fail(err)
552 }))
553 return
554 }
555 case "change": {
556 emit.single(FileSystem.WatchEventUpdate({ path }))
557 return
558 }
559 }
560 })
561 watcher.on("error", (error) => {
562 emit.fail(
563 new Error.SystemError({
564 module: "FileSystem",
565 reason: "Unknown",
566 method: "watch",
567 pathOrDescriptor: path,
568 cause: error
569 })
570 )
571 })
572 watcher.on("close", () => {
573 emit.end()
574 })
575 return watcher
576 }),
577 (watcher) => Effect.sync(() => watcher.close())
578 )
579 )
580
581const watch = (
582 backend: Option.Option<Context.Tag.Service<FileSystem.WatchBackend>>,

Callers 1

watchFunction · 0.85

Calls 7

statFunction · 0.85
syncMethod · 0.80
fromEffectMethod · 0.80
failMethod · 0.65
singleMethod · 0.65
endMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…