$promised->getLogger()->log("%s: %s\n", $promised->getName(), $promised->getDescription());
/* allow the object to be collected */
$promised->setGarbage(true);
}
}
/* start a pool of 8 threads to fulfill promises */
$manager = new PromiseManager(8);
/* get 100 random internal function names */
$functions = get_defined_functions();
foreach (array_rand($functions["internal"], 100) as $function) {
$names[] = $functions["internal"][$function];
}
$functions = $names;
/* create a logger for threads in the pool to share */
$logger = new SafeLogger();
/* create promises */
foreach ($functions as $index => $function) {
$functions[$index] = new Promise($manager, new DOMFetcher($logger, $function));
$functions[$index]->then(new DOMParser($functions[$index]))->then(new DOMPrinter($functions[$index]));
}
/* begin to collect ... */
while ($manager->hasWork()) {
$manager->collect(function ($task) {
return $task->isGarbage();
});
/* no need to collect agressively */
usleep(500000);
}
/* we are done */
$manager->shutdown();
}