Skip to content

Commit 2b7e4d0

Browse files
committed
return false to stop watching
1 parent 61295c2 commit 2b7e4d0

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ $watcher->watch(
3232
function (FsNotify\Event $event) {
3333
var_dump($event->getKind()); // kind of file/folder event
3434
var_dump($event->getPaths()); // paths
35+
return true; // return false if you do not want to continue
3536
}
3637
);
3738
```
@@ -50,7 +51,7 @@ class RecommendedWatcher
5051
public function remove(string $path): void;
5152

5253
/**
53-
* @param callable(Event): void $handle
54+
* @param callable(Event): bool $handle
5455
* @throws WatchException
5556
*/
5657
public function watch(callable $handle): void;

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ pub fn get_module() -> Module {
190190
let kind = php_event.get_mut_property("kind");
191191
*kind = php_kind.into();
192192

193-
handler.call([ZVal::from(php_event)])?;
193+
let call_result = handler.call([ZVal::from(php_event)])?;
194+
if call_result.expect_bool()? == false {
195+
break;
196+
}
194197
},
195198
Err(error) => return Err(NotifyError::new(error).into()),
196199
}

tests/php/recommended_watcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
$watcher->watch(function (FsNotify\Event $event) {
1313
var_dump($event->getKind());
1414
var_dump($event->getPaths());
15-
exit;
15+
return false;
1616
});

tests/php/test_exception.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try {
88
$watcher = new FsNotify\RecommendedWatcher();
99
$watcher->add(__DIR__ . '/unknown');
10-
$watcher->watch(fn () => null);
10+
$watcher->watch(fn () => false);
1111
} catch (FsNotify\WatchException) {
1212
echo "caught exception";
1313
}

0 commit comments

Comments
 (0)