Hyperlinkv0.8.0-beta.28

FileSystem

FileSystem.WatchBackendclasseffect/FileSystem.ts:1405
WatchBackend

Service key for file system watch backend implementations.

Details

This service provides the low-level file watching capabilities that can be implemented differently on various platforms (e.g., inotify on Linux, FSEvents on macOS, etc.).

Example (Providing a custom watch backend)

import { Effect, FileSystem, Option, Stream } from "effect"

// Custom watch backend implementation
const customWatchBackend = {
  register: (path: string, stat: FileSystem.File.Info) => {
    // Implementation would depend on platform
    return Option.some(Stream.empty) // Placeholder implementation
  }
}

// Provide custom watch backend
const program = Effect.gen(function*() {
  const fs = yield* FileSystem.FileSystem

  // File watching will use the custom backend
  const watcher = fs.watch("./directory")
})

const withCustomBackend = Effect.provideService(
  program,
  FileSystem.WatchBackend,
  customWatchBackend
)
file watcher
export class WatchBackend extends Context.Service<WatchBackend, {
  readonly register: (path: string, stat: File.Info) => Option.Option<Stream.Stream<WatchEvent, PlatformError>>
}>()("effect/platform/FileSystem/WatchBackend") {}