Skip to content

Commit 91b14a0

Browse files
committed
Add runWithStopCheck to replication factory
1 parent 635b8a5 commit 91b14a0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/MySQLReplication/MySQLReplicationFactory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ public function run(): void
104104
}
105105
}
106106

107+
/**
108+
* Run replication, checking $shouldStop callback on each iteration, to be able to gracefully stop the process.
109+
*
110+
* @param callable $shouldStop Returns true if the process should stop
111+
*/
112+
public function runWithStopCheck(callable $shouldStop): void
113+
{
114+
while (true) {
115+
if ($shouldStop()) {
116+
break;
117+
}
118+
119+
$this->consume();
120+
}
121+
}
122+
107123
public function consume(): void
108124
{
109125
$this->event->consume();

0 commit comments

Comments
 (0)