Skip to content

Commit c712812

Browse files
committed
Implement skeleton for isRunning()
1 parent fc5e96f commit c712812

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/AsyncTaskStatus.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class AsyncTaskStatus
1919
*/
2020
private string|null $encodedTaskID = null;
2121

22+
/**
23+
* Indicates whether the task is stopped.
24+
*
25+
* Note: the criteria is "pretty sure it is stopped"; once the task is stopped, it stays stopped.
26+
* @var bool
27+
*/
28+
private bool $isStopped = false;
29+
2230
/**
2331
* Constructs a status object.
2432
* @param string $taskID The task ID of the async task so to check its status.
@@ -43,4 +51,24 @@ public function getEncodedTaskID(): string
4351
}
4452
return $this->encodedTaskID;
4553
}
54+
55+
/**
56+
* Returns whether the AsyncTask is still running.
57+
*
58+
* Note: when this method detects that the task has stopped running, it will not recheck whether the task has restarted.
59+
* Use a fresh status object to track the (restarted) task.
60+
* @return bool
61+
*/
62+
public function isRunning(): bool
63+
{
64+
if ($this->isStopped) {
65+
return false;
66+
}
67+
// prove it is running
68+
$isRunning = false;
69+
if (!$isRunning) {
70+
$this->isStopped = true;
71+
}
72+
return $isRunning;
73+
}
4674
}

0 commit comments

Comments
 (0)