File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments