Skip to content

Commit a9751b3

Browse files
committed
execute the signal better
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 24ad367 commit a9751b3

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/Proxy/SpyProxy.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ function (ReflectionParameter $param) {
7171
$value = '[]';
7272
}
7373
$hookName = str_replace('$', '\$', $hookName);
74+
7475
return <<<EOT
7576
{$name} {
7677
\$this->operation = "{$hookName}";
7778
\$this->arguments = {$value};
78-
throw new \Exception('Not implemented');
79+
throw new \Bottledcode\DurablePhp\Proxy\SpyException('do not call outside of context');
7980
}
8081
EOT;
8182
}
@@ -84,7 +85,7 @@ function (ReflectionParameter $param) {
8485
public function {$name}({$params}){$return} {
8586
\$this->operation = "{$name}";
8687
\$this->arguments = func_get_args();
87-
throw new \Exception('Not implemented');
88+
throw new \Bottledcode\DurablePhp\Proxy\SpyException('do not call outside of context');
8889
}
8990
EOT;
9091
}
@@ -102,7 +103,24 @@ protected function impureSignal(ReflectionMethod $method): string
102103
protected function preamble(ReflectionClass $class): string
103104
{
104105
return <<<'EOT'
105-
public function __construct(private string|null &$operation = null, private array|null &$arguments = null) {}
106+
private string|null $operation {
107+
get => $this->op;
108+
set {
109+
if ($this->op !== null) {
110+
throw new \LogicException('Can only send one signal at a time');
111+
}
112+
}
113+
}
114+
private array|null $arguments {
115+
get => $this->args;
116+
set {
117+
if ($this->args !== null) {
118+
throw new \LogicException('Can only send one signal at a time');
119+
}
120+
}
121+
}
122+
123+
public function __construct(private string|null &$op = null, private array|null &$args = null) {}
106124
EOT;
107125
}
108126
}

src/RemoteEntityClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use Amp\Http\Client\HttpClient;
2828
use Amp\Http\Client\Request;
29+
use Bottledcode\DurablePhp\Proxy\SpyException;
2930
use Bottledcode\DurablePhp\Proxy\SpyProxy;
3031
use Bottledcode\DurablePhp\Search\EntityFilter;
3132
use Bottledcode\DurablePhp\State\EntityId;
@@ -37,7 +38,6 @@
3738
use Generator;
3839
use Override;
3940
use ReflectionFunction;
40-
use Throwable;
4141

4242
class RemoteEntityClient implements EntityClientInterface
4343
{
@@ -84,8 +84,8 @@ public function signal(EntityId|string $entityId, Closure $signal): void
8484
try {
8585
$class = new $spy($operationName, $arguments);
8686
$signal($class);
87-
} catch (Throwable) {
88-
// spies always throw
87+
} catch (SpyException) {
88+
// we have completed the spy
8989
}
9090
$this->signalEntity(
9191
is_string($entityId) ? EntityId($interfaceName, $entityId) : $entityId,

0 commit comments

Comments
 (0)