Refactored main class, improved a few things here and there. Looks polished enough
This commit is contained in:
parent
75c6062a3e
commit
411898af2a
14 changed files with 351 additions and 300 deletions
38
tests/jobs_test.php
Normal file
38
tests/jobs_test.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
// Import everything
|
||||
require 'ncc';
|
||||
require __DIR__ . DIRECTORY_SEPARATOR . 'ExampleClass.php';
|
||||
import('net.nosial.tamerlib');
|
||||
|
||||
// Initialize TamerLib
|
||||
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
|
||||
// Start 8 workers.
|
||||
\TamerLib\tm::createWorker(12, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
|
||||
|
||||
// For testing purposes
|
||||
$total_sleep = 0;
|
||||
|
||||
// Run 5 sleep jobs
|
||||
for($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$sleep_time = random_int(1, 5);
|
||||
\TamerLib\tm::sleep($sleep_time);
|
||||
$total_sleep += $sleep_time;
|
||||
}
|
||||
|
||||
// Run 30 pi jobs
|
||||
for($i = 0; $i < 30; $i++)
|
||||
{
|
||||
\TamerLib\tm::pi(50);
|
||||
}
|
||||
|
||||
// Wait for all the jobs to complete
|
||||
$start_time = time();
|
||||
\TamerLib\tm::wait(static function($job_id, $return){
|
||||
echo sprintf('Job %s completed with return value %s.', $job_id, $return) . PHP_EOL;
|
||||
});
|
||||
|
||||
// Script ends here once all the jobs are complete.
|
||||
echo sprintf('Total sleep time: %s seconds.', $total_sleep) . PHP_EOL;
|
||||
echo sprintf('Total execution time: %s seconds.', time() - $start_time) . PHP_EOL;
|
Loading…
Add table
Add a link
Reference in a new issue