| 9 | import { testLayer } from "../../../effect/test/FileSystem.test-utils.ts" |
| 10 | |
| 11 | const startWatch = <E, R>( |
| 12 | fs: FileSystem.FileSystem, |
| 13 | root: string, |
| 14 | watch: () => Stream.Stream<FileSystem.WatchEvent, E, R> |
| 15 | ) => |
| 16 | Effect.gen(function*() { |
| 17 | const ready = yield* Deferred.make<void>() |
| 18 | const readyName = ".watch-ready" |
| 19 | const fiber = yield* watch().pipe( |
| 20 | Stream.tap((event) => |
| 21 | event.path === readyName |
| 22 | ? Deferred.succeed(ready, undefined) |
| 23 | : Effect.void |
| 24 | ), |
| 25 | Stream.dropUntil((event) => event.path === readyName), |
| 26 | Stream.filter((event) => event.path !== readyName), |
| 27 | Stream.runHead, |
| 28 | Effect.flatMap(Effect.fromOption), |
| 29 | Effect.forkChild |
| 30 | ) |
| 31 | const signalFiber = yield* Effect.sleep("10 millis").pipe( |
| 32 | TestClock.withLive, |
| 33 | Effect.andThen(fs.writeFileString(`${root}/${readyName}`, "")), |
| 34 | Effect.forever, |
| 35 | Effect.forkChild |
| 36 | ) |
| 37 | yield* Deferred.await(ready).pipe( |
| 38 | Effect.raceFirst(Fiber.join(fiber).pipe(Effect.asVoid)), |
| 39 | Effect.ensuring(Fiber.interrupt(signalFiber)) |
| 40 | ) |
| 41 | return fiber |
| 42 | }) |
| 43 | |
| 44 | describe("FileSystem", () => { |
| 45 | testLayer(NodeFileSystem.layer) |