Skip to content

Instantly share code, notes, and snippets.

@jensscherbl
Last active June 3, 2026 12:59
Show Gist options
  • Select an option

  • Save jensscherbl/9e7b5c416fbd0a0f57c3491f9ad82807 to your computer and use it in GitHub Desktop.

Select an option

Save jensscherbl/9e7b5c416fbd0a0f57c3491f9ad82807 to your computer and use it in GitHub Desktop.
<?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