Last active
June 3, 2026 12:59
-
-
Save jensscherbl/9e7b5c416fbd0a0f57c3491f9ad82807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| final class Runnable | |
| { | |
| private $callables; | |
| public function __construct(callable ...$callables) | |
| { | |
| $this->callables = $callables; | |
| } | |
| public function run() | |
| { | |
| do { | |
| $callable = array_shift($this->callables); | |
| $callable(); | |
| } while (count($this->callables) > 0); | |
| } | |
| } | |
| $runnable = new Runnable( | |
| function () { echo 'Task 1.' . PHP_EOL; }, | |
| function () { echo 'Task 2.' . PHP_EOL; }, | |
| function () { echo 'Task 3.' . PHP_EOL; }, | |
| function () { echo 'Task 4.' . PHP_EOL; }, | |
| function () { echo 'Task 5.' . PHP_EOL; } | |
| ); | |
| fhread_create( | |
| $runnable, | |
| $id, | |
| $handle | |
| ); | |
| fhread_join( | |
| $handle, | |
| $error | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment