( path: string, options?: FileSystem.WatchOptions )
| 391 | tryPromise("utimes", path, () => Deno.utime(path, atime, mtime)) |
| 392 | |
| 393 | const 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 | |
| 427 | const watch = ( |
| 428 | backend: Option.Option<FileSystem.WatchBackend["Service"]>, |
no test coverage detected