Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit daee243

Browse files
committed
Defer calls
1 parent 039a304 commit daee243

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/AbstractGeneratedProxy.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ final protected function proxyCallToMainThread(string $method, array $args)
5555
return $result;
5656
}
5757

58+
/**
59+
* @param mixed[] $args
60+
*
61+
* @return mixed|void
62+
*/
63+
final protected function deferCallToMainThread(string $method, array $args)
64+
{
65+
$input = new Channel(1);
66+
$call = new Call(
67+
$input,
68+
$this->hash,
69+
spl_object_hash($this),
70+
$method,
71+
$args,
72+
);
73+
74+
if ($this->deferredCallHandler instanceof DeferredCallHandler) {
75+
$this->deferredCallHandler->call($call);
76+
$this->deferredCallHandler->commit($this->out);
77+
} else {
78+
$this->out->send($call);
79+
}
80+
81+
$result = $input->recv();
82+
$input->close();
83+
84+
return $result;
85+
}
86+
5887
/**
5988
* @param mixed[] $args
6089
*/

src/Composer/InterfaceProxier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function populateMethod(Node\Stmt\ClassMethod $method): Node\Stmt\ClassM
190190

191191
$methodBody = new Node\Expr\MethodCall(
192192
new Node\Expr\Variable('this'),
193-
$this->isMethodVoid($method) ? ($this->isDeferrable($method) ? 'deferNotifyMainThread' : 'proxyNotifyMainThread') : 'proxyCallToMainThread',
193+
$this->isMethodVoid($method) ? ($this->isDeferrable($method) ? 'deferNotifyMainThread' : 'proxyNotifyMainThread') : ($this->isDeferrable($method) ? 'deferCallToMainThread' : 'proxyCallToMainThread'),
194194
iterator_to_array($this->methodCallArguments($method))
195195
);
196196

0 commit comments

Comments
 (0)