Added worker test
This commit is contained in:
parent
478d12fd43
commit
0f96c0ce60
1 changed files with 44 additions and 0 deletions
44
tests/worker.php
Normal file
44
tests/worker.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
require __DIR__ . DIRECTORY_SEPARATOR . 'ExampleClass.php';
|
||||
import('net.nosial.tamerlib');
|
||||
|
||||
// Initialize as a worker, will fail if the process is executed directly
|
||||
\TamerLib\tm::initalize(\TamerLib\Enums\TamerMode::WORKER);
|
||||
|
||||
// Callback Examples
|
||||
\TamerLib\tm::addFunction('sleep', function($sleep_time){
|
||||
sleep($sleep_time);
|
||||
return $sleep_time;
|
||||
});
|
||||
\TamerLib\tm::addFunction('calculate_pi', function($iterations){
|
||||
$pi = 0;
|
||||
$sign = 1;
|
||||
for($i = 0; $i < $iterations; $i++)
|
||||
{
|
||||
$pi += $sign * (1 / (2 * $i + 1));
|
||||
$sign *= -1;
|
||||
}
|
||||
return $pi * 4;
|
||||
});
|
||||
|
||||
// Function pointer examples
|
||||
$example_class = new ExampleClass();
|
||||
\TamerLib\tm::addFunction('getValue', [$example_class, 'get']);
|
||||
\TamerLib\tm::addFunction('setValue', [$example_class, 'set']);
|
||||
\TamerLib\tm::addFunction('valueExists', [$example_class, 'exists']);
|
||||
\TamerLib\tm::addFunction('clearValues', [$example_class, 'clear']);
|
||||
|
||||
// Run forest, run!
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
\TamerLib\tm::run();
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
print($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue