|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of Temporal package. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace Temporal\Internal\Transport; |
| 13 | + |
| 14 | +use React\Promise\PromiseInterface; |
| 15 | +use Temporal\Worker\Transport\Command\CommandInterface; |
| 16 | +use Temporal\Worker\Transport\Command\RequestInterface; |
| 17 | +use Temporal\Worker\Transport\Command\ServerResponseInterface; |
| 18 | +use Temporal\Workflow\WorkflowContextInterface; |
| 19 | + |
| 20 | +/** |
| 21 | + * @internal Client is an internal library class, please do not use it in your code. |
| 22 | + * @psalm-internal Temporal\Internal\Transport |
| 23 | + */ |
| 24 | +final class DetachedClient implements ClientInterface |
| 25 | +{ |
| 26 | + /** @var list<int> */ |
| 27 | + private array $requests = []; |
| 28 | + |
| 29 | + /** |
| 30 | + * @param \Closure(list<int>): void $cleanup Handler that removes requests from the parent using their IDs. |
| 31 | + */ |
| 32 | + public function __construct( |
| 33 | + private ClientInterface $parent, |
| 34 | + private \Closure $cleanup, |
| 35 | + ) {} |
| 36 | + |
| 37 | + #[\Override] |
| 38 | + public function request(RequestInterface $request, ?WorkflowContextInterface $context = null): PromiseInterface |
| 39 | + { |
| 40 | + $this->requests[] = $request->getID(); |
| 41 | + return $this->parent->request($request, $context); |
| 42 | + } |
| 43 | + |
| 44 | + #[\Override] |
| 45 | + public function send(CommandInterface $request): void |
| 46 | + { |
| 47 | + $this->parent->send($request); |
| 48 | + } |
| 49 | + |
| 50 | + #[\Override] |
| 51 | + public function isQueued(CommandInterface $command): bool |
| 52 | + { |
| 53 | + return $this->parent->isQueued($command); |
| 54 | + } |
| 55 | + |
| 56 | + #[\Override] |
| 57 | + public function cancel(CommandInterface $command): void |
| 58 | + { |
| 59 | + $this->parent->cancel($command); |
| 60 | + } |
| 61 | + |
| 62 | + #[\Override] |
| 63 | + public function reject(CommandInterface $command, \Throwable $reason): void |
| 64 | + { |
| 65 | + $this->parent->reject($command, $reason); |
| 66 | + } |
| 67 | + |
| 68 | + #[\Override] |
| 69 | + public function dispatch(ServerResponseInterface $response): void |
| 70 | + { |
| 71 | + $this->parent->dispatch($response); |
| 72 | + } |
| 73 | + |
| 74 | + #[\Override] |
| 75 | + public function fork(): ClientInterface |
| 76 | + { |
| 77 | + return $this->parent->fork(); |
| 78 | + } |
| 79 | + |
| 80 | + public function destroy(): void |
| 81 | + { |
| 82 | + $this->requests === [] or ($this->cleanup)($this->requests); |
| 83 | + $this->requests = []; |
| 84 | + unset($this->parent, $this->cleanup); |
| 85 | + } |
| 86 | +} |
0 commit comments