Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supporting for React/Promises v3 #351

Merged
merged 7 commits into from
Sep 15, 2023
Merged
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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
"grpc/grpc": "^1.42",
"nesbot/carbon": "^2.66",
"psr/log": "^2.0 || ^3.0",
"react/promise": "^2.9",
"ramsey/uuid": "^4.7",
"react/promise": "2.9 || ^3.0",
"roadrunner-php/roadrunner-api-dto": "^1.3",
"roadrunner-php/version-checker": "^1.0",
"spiral/attributes": "^2.8 || ^3.0",
"spiral/roadrunner": "^v2023.2",
"spiral/roadrunner-cli": "^2.5",
"spiral/roadrunner-kv": "^4.0",
"spiral/roadrunner-worker": "^3.0",
"symfony/filesystem": "^4.4.20 || ^5.0 || ^6.0",
"symfony/http-client": "^4.4.27 || ^5.0 || ^6.0",
"symfony/process": "^5.4 || ^6.0",
"roadrunner-php/version-checker": "^1.0",
"spiral/roadrunner": "^v2023.2"
"symfony/process": "^5.4 || ^6.0"
},
"autoload": {
"psr-4": {
Expand Down
114 changes: 28 additions & 86 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@
<code><![CDATA[$command->getID()]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Internal/Transport/CompletableResult.php">
<InvalidArgument>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
</InvalidArgument>
<PossiblyNullArgument>
<code>$value</code>
</PossiblyNullArgument>
</file>
<file src="src/Internal/Transport/Request/NewTimer.php">
<PossiblyNullPropertyFetch>
<code><![CDATA[CarbonInterval::make($interval)->totalMilliseconds]]></code>
Expand Down Expand Up @@ -939,27 +948,18 @@
</MoreSpecificReturnType>
</file>
<file src="src/Internal/Workflow/Process/Process.php">
<InternalClass>
<code>Scope</code>
<code>parent::__construct($services, $ctx)</code>
<code>parent::start($handler, $values)</code>
</InternalClass>
<InternalMethod>
<code>createScope</code>
<code>getContext</code>
<code>makeCurrent</code>
<code>onClose</code>
<code>parent::__construct($services, $ctx)</code>
<code>parent::start($handler, $values)</code>
<code>promise</code>
<code>startSignal</code>
</InternalMethod>
<InvalidDocblock>
<code>class Process extends Scope implements ProcessInterface</code>
</InvalidDocblock>
<MissingClosureParamType>
<code>$result</code>
</MissingClosureParamType>
<MissingParamType>
<code>$result</code>
</MissingParamType>
<MissingTemplateParam>
<code>ProcessInterface</code>
</MissingTemplateParam>
<PropertyNotSetInConstructor>
<code>Process</code>
</PropertyNotSetInConstructor>
Expand All @@ -973,69 +973,10 @@
<ArgumentTypeCoercion>
<code><![CDATA[$this->context]]></code>
</ArgumentTypeCoercion>
<InternalClass>
<code><![CDATA[new Scope($this->services, $this->context)]]></code>
</InternalClass>
<InternalMethod>
<code>attach</code>
<code>call</code>
<code>callSignalHandler</code>
<code>createScope</code>
<code>createScope</code>
<code>defer</code>
<code>defer</code>
<code>handleError</code>
<code>handleError</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code><![CDATA[new Scope($this->services, $this->context)]]></code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>onClose</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onResult</code>
<code>start</code>
</InternalMethod>
<InternalProperty>
<code><![CDATA[$scope->detached]]></code>
<code><![CDATA[$scope->layer]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelled]]></code>
<code><![CDATA[$this->context]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->deferred]]></code>
<code><![CDATA[$this->exception]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onClose]]></code>
<code><![CDATA[$this->result]]></code>
<code><![CDATA[$this->scopeContext]]></code>
<code><![CDATA[$this->services]]></code>
</InternalProperty>
<InvalidArgument>
<code>$onFulfilled</code>
<code>$onRejected</code>
</InvalidArgument>
<LessSpecificReturnStatement>
<code><![CDATA[$this->context]]></code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -1067,6 +1008,9 @@
<code>resolveConditions</code>
<code>resolveConditions</code>
</UndefinedInterfaceMethod>
<UnusedClosureParam>
<code>$e</code>
</UnusedClosureParam>
</file>
<file src="src/Internal/Workflow/ProcessCollection.php">
<DocblockTypeContradiction>
Expand All @@ -1082,14 +1026,6 @@
</PossiblyNullReference>
</file>
<file src="src/Internal/Workflow/ScopeContext.php">
<InternalMethod>
<code>getLayer</code>
<code>getLayer</code>
<code>isCancelled</code>
<code>onAwait</code>
<code>startScope</code>
<code>startScope</code>
</InternalMethod>
<PropertyNotSetInConstructor>
<code>$onRequest</code>
<code>$parent</code>
Expand Down Expand Up @@ -1153,6 +1089,12 @@
<code>$promiseOrValue</code>
<code>$promiseOrValue</code>
</MissingParamType>
<PossiblyInvalidArgument>
<code>$reasons</code>
</PossiblyInvalidArgument>
<TooManyArguments>
<code>$reduce($c, $value, $i++, $total)</code>
</TooManyArguments>
</file>
<file src="src/Worker/ActivityInvocationCache/ActivityInvocationCacheInterface.php">
<MissingParamType>
Expand Down
63 changes: 63 additions & 0 deletions src/Internal/Promise/CancellationQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Temporal\Internal\Promise;

/**
* @internal
* @psalm-internal Temporal
*/
class CancellationQueue
{
private bool $started = false;
private array $queue = [];

public function __invoke()
{
if ($this->started) {
return;
}

$this->started = true;
$this->drain();
}

public function enqueue(mixed $cancellable): void
{
if (!\is_object($cancellable)
|| !\method_exists($cancellable, 'then')
|| !\method_exists($cancellable, 'cancel')
) {
return;
}

$length = \array_push($this->queue, $cancellable);

if ($this->started && 1 === $length) {
$this->drain();
}
}

private function drain(): void
{
for ($i = \key($this->queue); isset($this->queue[$i]); $i++) {
$cancellable = $this->queue[$i];

$exception = null;

try {
$cancellable->cancel();
} catch (\Throwable $exception) {
}

unset($this->queue[$i]);

if ($exception) {
throw $exception;
}
}

$this->queue = [];
}
}
89 changes: 89 additions & 0 deletions src/Internal/Promise/Reasons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace Temporal\Internal\Promise;

use ArrayAccess;
use Countable;
use Iterator;
use RuntimeException;
use Traversable;

/**
* @internal
* @psalm-internal Temporal
* @template TKey of array-key
* @template TValue of Traversable
* @implements Iterator<TKey, TValue>
* @implements ArrayAccess<TKey, TValue>
*/
final class Reasons extends RuntimeException implements Iterator, ArrayAccess, Countable
{
/**
* @param array<TKey, TValue> $collection
*/
public function __construct(
public array $collection,
) {
parent::__construct();
}

public function current(): mixed
{
return \current($this->collection);
}

public function next(): void
{
\next($this->collection);
}

public function key(): string|int|null
{
return \key($this->collection);
}

public function valid(): bool
{
return null !== \key($this->collection);
}

public function rewind(): void
{
\reset($this->collection);
}

public function offsetExists(mixed $offset): bool
{
return isset($this->collection[$offset]);
}

/**
* @param TKey $offset
* @return TValue
*/
public function offsetGet(mixed $offset): Traversable
{
return $this->collection[$offset];
}

/**
* @param TKey $offset
* @param TValue $value
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->collection[$offset] = $value;
}

public function offsetUnset(mixed $offset): void
{
unset($this->collection[$offset]);
}

public function count(): int
{
return \count($this->collection);
}
}
Loading