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

Function startWatch

packages/platform/node-shared/test/NodeFileSystem.test.ts:11–42  ·  view source on GitHub ↗
(
  fs: FileSystem.FileSystem,
  root: string,
  watch: () => Stream.Stream<FileSystem.WatchEvent, E, R>
)

Source from the content-addressed store, hash-verified

9import { testLayer } from "../../../effect/test/FileSystem.test-utils.ts"
10
11const 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
44describe("FileSystem", () => {
45 testLayer(NodeFileSystem.layer)

Callers 1

Calls 9

filterMethod · 0.80
joinMethod · 0.80
makeMethod · 0.65
pipeMethod · 0.65
sleepMethod · 0.65
awaitMethod · 0.65
watchFunction · 0.50
succeedMethod · 0.45
interruptMethod · 0.45

Tested by

no test coverage detected