Skip to content

Commit

Permalink
Fix: Clear next ticks (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Nov 20, 2023
1 parent 3335c0b commit 30d45fd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/EtlExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public function processItem(mixed $item, mixed $key, EtlState $state): void
private function consumeNextTick(EtlState $state): void
{
foreach ($state->nextTickCallbacks as $callback) {
($callback)($state);
$state->nextTickCallbacks->detach($callback);
($callback)($state);
}
}

Expand Down Expand Up @@ -212,10 +212,14 @@ private function flush(EtlState $state, bool $early): mixed
*/
private function terminate(EtlState $state): EtlState
{
try {
$this->consumeNextTick($state);
} catch (SkipRequest|StopRequest) {
// Ensure everything has been cleared
while (0 !== count($state->nextTickCallbacks)) {
try {
$this->consumeNextTick($state);
} catch (SkipRequest|StopRequest) {
}
}

$output = $this->flush($state->getLastVersion(), false);

$state = $state->getLastVersion();
Expand Down

0 comments on commit 30d45fd

Please sign in to comment.