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

Function watchNative

packages/platform/deno/src/DenoFileSystem.ts:448–482  ·  view source on GitHub ↗
(
  path: string,
  options?: FileSystem.WatchOptions
)

Source from the content-addressed store, hash-verified

446 tryPromise("utimes", path, () => Deno.utime(path, atime, mtime))
447
448const watchNative = (
449 path: string,
450 options?: FileSystem.WatchOptions
451): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> =>
452 Stream.unwrap(
453 Effect.map(
454 Effect.try({
455 try: () => Deno.watchFs(path, { recursive: options?.recursive ?? false }),
456 catch: handleError("FileSystem", "watch", path)
457 }),
458 (watcher) => {
459 options?.onReady?.()
460 return Stream.fromAsyncIterable(watcher, handleError("FileSystem", "watch", path)).pipe(
461 Stream.flatMap((event): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> => {
462 switch (event.kind) {
463 case "create":
464 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Create" as const, path }))
465 case "modify":
466 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Update" as const, path }))
467 case "remove":
468 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Remove" as const, path }))
469 case "rename":
470 return Stream.mapEffect(Stream.fromIterable(event.paths), (path) =>
471 Effect.match(stat(path), {
472 onFailure: () => ({ _tag: "Remove" as const, path }),
473 onSuccess: () => ({ _tag: "Create" as const, path })
474 }))
475 default:
476 return Stream.empty
477 }
478 })
479 )
480 }
481 )
482 )
483
484const watch = (
485 backend: Option.Option<FileSystem.WatchBackend["Service"]>,

Callers 1

watchFunction · 0.85

Calls 5

handleErrorFunction · 0.90
onReadyMethod · 0.80
statFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected