Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"fixcs": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff --verbose",
"infection": "tools/infection/vendor/bin/infection --show-mutations",
"normalize": "@composer bin composer-normalize normalize --diff ../../composer.json",
"phpstan": "tools/phpstan/vendor/bin/phpstan analyze",
"phpstan": "tools/phpstan/vendor/bin/phpstan analyze --memory-limit=512M",
"pre-command-run": "mkdir -p var",
"psalm": "tools/psalm/vendor/bin/psalm --show-info --no-diff --no-cache",
"rector": "tools/rector/vendor/bin/rector process",
Expand Down
11 changes: 10 additions & 1 deletion src/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ public function consumeIterator(
/** @var Internal\QueueIterator<DeliveryMessage> $iterator */
$iterator = Internal\QueueIterator::buffered($consumerTag, $this, $size);

$canceller = new Canceller(
$iterator->complete(...),
$iterator->cancel(...),
$iterator->abandon(...),
);

$this->cancellations->add($consumerTag, $canceller);

$this->consume(
callback: $iterator->push(...),
queue: $queue,
Expand Down Expand Up @@ -339,6 +347,7 @@ public function consumeBatch(
$canceller = new Canceller(
$iterator->complete(...),
$iterator->cancel(...),
$iterator->abandon(...),
);

$this->cancellations->add($consumerTag, $canceller);
Expand Down Expand Up @@ -782,7 +791,7 @@ public function abandon(\Throwable $e): void
{
$this->hooks->reject($this->channelId, $e);
$this->hooks->unsubscribe($this->channelId);
$this->cancellations->cancelAll(error: $e);
$this->cancellations->abandon($e);
$this->supervisor->stop();
$this->closed = new Sync\Once(static fn(): bool => true);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Internal/Cancellation/CancellationStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public function cancel(string $consumerTag, bool $noWait = false, ?\Throwable $e
}
}

public function abandon(\Throwable $e): void
{
try {
foreach ($this->cancellers as $canceller) {
$canceller->abandon($e);
}
} finally {
$this->cancellers = [];
}
}

public function cancelAll(bool $noWait = false, ?\Throwable $error = null): void
{
try {
Expand Down
16 changes: 16 additions & 0 deletions src/Internal/Cancellation/Canceller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ final class Canceller
/**
* @param callable(bool): void $complete
* @param callable(\Throwable, bool): void $cancel
* @param callable(\Throwable): void $abandon
*/
public function __construct(
private readonly mixed $complete,
private readonly mixed $cancel,
private readonly mixed $abandon,
) {
$this->deferred = new DeferredCancellation();
}
Expand All @@ -46,6 +48,20 @@ public function cancel(bool $noWait = false, ?\Throwable $e = null): void
}
}

public function abandon(\Throwable $e): void
{
if ($this->cancelled) {
return;
}

try {
($this->abandon)($e);
$this->deferred->cancel();
} finally {
$this->cancelled = true;
}
}

public function cancellation(): Cancellation
{
return $this->deferred->getCancellation();
Expand Down
19 changes: 15 additions & 4 deletions src/Internal/QueueIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@ public function push(mixed $delivery): void

public function complete(bool $noWait = false): void
{
$this->channel->cancel($this->consumerTag, $noWait);
$this->queue->complete();
if (!$this->queue->isComplete()) {
$this->queue->complete();
$this->channel->cancel($this->consumerTag, $noWait);
}
}

public function cancel(\Throwable $e, bool $noWait = false): void
{
$this->channel->cancel($this->consumerTag, $noWait);
$this->queue->error($e);
if (!$this->queue->isComplete()) {
$this->queue->error($e);
$this->channel->cancel($this->consumerTag, $noWait);
}
}

public function abandon(\Throwable $e): void
{
if (!$this->queue->isComplete()) {
$this->queue->error($e);
}
}

public function continue(?Cancellation $cancellation = null): bool
Expand Down
2 changes: 2 additions & 0 deletions src/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function complete(bool $noWait = false): void;
*/
public function cancel(\Throwable $e, bool $noWait = false): void;

public function abandon(\Throwable $e): void;

/**
* @throws CancelledException
*/
Expand Down
Loading