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

Function watchNative

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

Source from the content-addressed store, hash-verified

391 tryPromise("utimes", path, () => Deno.utime(path, atime, mtime))
392
393const watchNative = (
394 path: string,
395 options?: FileSystem.WatchOptions
396): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> =>
397 Stream.unwrap(
398 Effect.map(
399 Effect.try({
400 try: () => Deno.watchFs(path, { recursive: options?.recursive ?? false }),
401 catch: handleError("FileSystem", "watch", path)
402 }),
403 (watcher) =>
404 Stream.fromAsyncIterable(watcher, handleError("FileSystem", "watch", path)).pipe(
405 Stream.flatMap((event): Stream.Stream<FileSystem.WatchEvent, PlatformError.PlatformError> => {
406 switch (event.kind) {
407 case "create":
408 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Create" as const, path }))
409 case "modify":
410 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Update" as const, path }))
411 case "remove":
412 return Stream.map(Stream.fromIterable(event.paths), (path) => ({ _tag: "Remove" as const, path }))
413 case "rename":
414 return Stream.mapEffect(Stream.fromIterable(event.paths), (path) =>
415 Effect.match(stat(path), {
416 onFailure: () => ({ _tag: "Remove" as const, path }),
417 onSuccess: () => ({ _tag: "Create" as const, path })
418 }))
419 default:
420 return Stream.empty
421 }
422 })
423 )
424 )
425 )
426
427const watch = (
428 backend: Option.Option<FileSystem.WatchBackend["Service"]>,

Callers 1

watchFunction · 0.85

Calls 4

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

Tested by

no test coverage detected