Skip to content

Commit 3eec172

Browse files
committed
require innmind/file-watch 4
1 parent b0ac9a3 commit 3eec172

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- `Innmind\OperatingSystem\Ports\Unix::of()` is now declared `internal`
1919
- `Innmind\OperatingSystem\Remote\Generic::of()` is now declared `internal`
2020
- `Innmind\OperatingSystem\Ports\Sockets::of()` is now declared `internal`
21+
- Requires `innmind/file-watch:~4.0`
2122

2223
## 4.2.0 - 2023-12-14
2324

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"innmind/http-transport": "~7.2",
2525
"innmind/time-warp": "~3.0",
2626
"innmind/signals": "~3.0",
27-
"innmind/file-watch": "~3.1",
27+
"innmind/file-watch": "~4.0",
2828
"innmind/stream": "~4.0",
2929
"formal/access-layer": "^2.0",
3030
"innmind/io": "~2.7"

documentation/use_cases/filesystem.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,23 @@ It is a great way to forget about where the tmp folder is located and simply foc
112112
A pattern we don't see much in PHP is an infinite loop to react to an event to perform another task. Here we can build such pattern by watching for changes in a file or a directory.
113113

114114
```php
115-
use Innmind\FileWatch\Stop;
116-
use Innmind\Immutable\Either;
115+
use Innmind\FileWatch\Continuation;
117116

118117
$runTests = $os->filesystem()->watch(Path::of('/path/to/project/src/'));
119118

120-
$count = $runTests(0, function(int $count) use ($os): Either {
119+
$count = $runTests(0, function(int $count, Continuation $continuation) use ($os): Continuation {
121120
if ($count === 42) {
122-
return Either::left(Stop::of($count));
121+
return $continuation->stop($count);
123122
}
124123

125124
$os->control()->processes()->execute($phpunitCommand);
126125

127-
return Either::right(++$count);
126+
return $continuation->continue(++$count);
128127
});
129128
```
130129

131-
Here it will run phpunit tests every time the `src/` folder changes. Concrete examples of this pattern can be found in [`innmind/lab-station`](https://github.com/Innmind/LabStation/blob/develop/src/Agent/WatchSources.php#L38) to run a suite of tools when sources change or in [`halsey/journal`](https://github.com/halsey-php/journal/blob/develop/src/Command/Preview.php#L58) to rebuild the website when the markdown files change.
130+
Here it will run phpunit tests every time the `src/` folder changes. Concrete examples of this pattern can be found in [`innmind/lab-station`](https://github.com/Innmind/LabStation/blob/develop/src/Agent/WatchSources.php#L38) to run a suite of tools when sources change.
132131

133-
This operation is a bit like an `array_reduce` as you can keep a state record between each calls of the callable via the first argument (here `0`, but it can be anything) and the argument of your callable will be the previous value returned by `Either::right()`.
132+
This operation is a bit like an `array_reduce` as you can keep a state record between each calls of the callable via the first argument (here `0`, but it can be anything) and the argument of your callable will be the previous value returned by `$continuation->continue()`.
134133

135-
**Important**: since there is not builtin way to watch for changes in a directory it checks the directory every second, so use it with care. Watching an individual file is a bit safer as it uses the `tail` command so there is no `sleep()` used.
134+
**Important**: since there is no builtin way to watch for changes in a directory it checks the directory every second, so use it with care. Watching an individual file is a bit safer as it uses the `tail` command so there is no `sleep()` used.

0 commit comments

Comments
 (0)