@@ -35,27 +35,23 @@ $watch = Factory::build(
3535 new Usleep,
3636);
3737
38- $count = $watch(Path::of('/to/some/file/or/folder'))(0, function(int $count): Either {
38+ $count = $watch(Path::of('/to/some/file/or/folder'))(0, function(int $count, Continuation $continuation ): Continuation {
3939 // this function is called every time the file is modified
4040 ++$count;
4141
4242 if ($count === 42) {
43- // by returning a Stop instance on the left side it will instruct to
44- // stop watching for changes and the value in the Stop will be moved on
45- // the right side to the caller
46- return Either::left(Stop::of($count));
43+ // This will stop watching the folder for changes and return the count
44+ return $continuation->stop($count);
4745 }
4846
49- if ($forSomeReason) {
50- // by returning a left value it will stop watching for changes and the
51- // Either will be returned as is to the caller
52- return Either::left($someReason);
53- }
54-
55- // by returning a right side it will instruct to continue watching for changes
56- // and the value will be passed to this callable the next time it's called
57- return Either::right($count);
58- });
47+ // This will instruct to continue watching for changes and the value will be
48+ // passed to this callable the next time it's called
49+ return $continuation->continue($count);
50+ })->match(
51+ static fn(int $count) => $count, // always 42 as it's the stopping value
52+ static fn() => throw new \RuntimeException('Failed to watch for changes'),
53+ );
5954```
6055
61- ** Note** : The function may be called multiple times for an single change due to the way ` tail ` and ` stat ` works.
56+ > [ !WARNING]
57+ > The function may be called multiple times for an single change due to the way ` tail ` and ` stat ` works.
0 commit comments