diff --git a/src/MySQLReplication/MySQLReplicationFactory.php b/src/MySQLReplication/MySQLReplicationFactory.php index 9a692e6..ebff21c 100644 --- a/src/MySQLReplication/MySQLReplicationFactory.php +++ b/src/MySQLReplication/MySQLReplicationFactory.php @@ -104,6 +104,22 @@ public function run(): void } } + /** + * Run replication, checking $shouldStop callback on each iteration, to be able to gracefully stop the process. + * + * @param callable $shouldStop Returns true if the process should stop + */ + public function runWithStopCheck(callable $shouldStop): void + { + while (true) { + if ($shouldStop()) { + break; + } + + $this->consume(); + } + } + public function consume(): void { $this->event->consume();