Skip to content

Commit

Permalink
Fix signatures for Workflow::await and Workflow::awaitWithTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Oct 9, 2024
1 parent db4f91f commit 1ab3c6b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
11 changes: 3 additions & 8 deletions src/Internal/Workflow/WorkflowContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public function upsertSearchAttributes(array $searchAttributes): void
/**
* {@inheritDoc}
*/
public function await(...$conditions): PromiseInterface
public function await(callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
return $this->callsInterceptor->with(
fn(AwaitInput $input): PromiseInterface => $this->awaitRequest(...$input->conditions),
Expand All @@ -565,7 +565,7 @@ public function await(...$conditions): PromiseInterface
/**
* {@inheritDoc}
*/
public function awaitWithTimeout($interval, ...$conditions): PromiseInterface
public function awaitWithTimeout($interval, callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
$intervalObject = DateInterval::parse($interval, DateInterval::FORMAT_SECONDS);

Expand Down Expand Up @@ -661,17 +661,12 @@ public function destroy(): void
unset($this->workflowInstance);
}

/**
* @param callable|Mutex|PromiseInterface ...$conditions
*/
protected function awaitRequest(...$conditions): PromiseInterface
protected function awaitRequest(callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
$result = [];
$conditionGroupId = Uuid::v4();

foreach ($conditions as $condition) {
\assert(\is_callable($condition) || $condition instanceof PromiseInterface || $condition instanceof Mutex);

// Wrap Mutex into callable
$condition instanceof Mutex and $condition = static fn(): bool => !$condition->isLocked();

Expand Down
4 changes: 2 additions & 2 deletions src/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static function asyncDetached(callable $task): CancellationScopeInterface
* @param callable|PromiseInterface|Mutex ...$conditions
* @return PromiseInterface
*/
public static function await(...$conditions): PromiseInterface
public static function await(callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
return self::getCurrentContext()->await(...$conditions);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ public static function await(...$conditions): PromiseInterface
* @param callable|PromiseInterface|Mutex ...$conditions
* @return PromiseInterface<bool>
*/
public static function awaitWithTimeout($interval, ...$conditions): PromiseInterface
public static function awaitWithTimeout($interval, callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
return self::getCurrentContext()->awaitWithTimeout($interval, ...$conditions);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Workflow/WorkflowContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function newUntypedActivityStub(
* @param callable|Mutex|PromiseInterface ...$conditions
* @return PromiseInterface
*/
public function await(...$conditions): PromiseInterface;
public function await(callable|Mutex|PromiseInterface ...$conditions): PromiseInterface;

/**
* Checks if any conditions were met or the timeout was reached.
Expand All @@ -324,7 +324,7 @@ public function await(...$conditions): PromiseInterface;
* @param callable|Mutex|PromiseInterface ...$conditions
* @return PromiseInterface<bool>
*/
public function awaitWithTimeout($interval, ...$conditions): PromiseInterface;
public function awaitWithTimeout($interval, callable|Mutex|PromiseInterface ...$conditions): PromiseInterface;

/**
* Returns a complete trace of the last calls (for debugging).
Expand Down
4 changes: 2 additions & 2 deletions tests/Acceptance/Harness/Schedule/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public static function check(

// Confirm simple list
$found = false;
$deadline = \microtime(true) + 10;
$findDeadline = \microtime(true) + 10;
find:
foreach ($client->listSchedules() as $schedule) {
if ($schedule->scheduleId === $scheduleId) {
$found = true;
break;
}
}
if (!$found and \microtime(true) < $deadline) {
if (!$found and \microtime(true) < $findDeadline) {
goto find;
}

Expand Down

0 comments on commit 1ab3c6b

Please sign in to comment.