Progress on closures
This commit is contained in:
parent
39d1084a3f
commit
f88f453578
13 changed files with 427 additions and 144 deletions
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
|
||||
use Tamer\Objects\Job;
|
||||
use Tamer\Objects\Task;
|
||||
|
||||
import('net.nosial.tamerlib', 'latest');
|
||||
|
||||
$client = new \Tamer\Protocols\GearmanClient();
|
||||
$client->addServer();
|
||||
|
||||
$client->addTask(new Task('sleep', '5', function(Job $job) {
|
||||
echo "Task {$job->getId()} completed with data: {$job->getData()} \n";
|
||||
}));
|
||||
|
||||
|
||||
$client->doTasks();
|
26
tests/gearman_client.php
Normal file
26
tests/gearman_client.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
|
||||
use Tamer\Objects\JobResults;
|
||||
use Tamer\Objects\Task;
|
||||
|
||||
import('net.nosial.tamerlib', 'latest');
|
||||
|
||||
$client = new \Tamer\Protocols\GearmanClient();
|
||||
$client->addServer();
|
||||
|
||||
$client->doBackground(new Task('sleep', '5'));
|
||||
|
||||
|
||||
$client->addTask(new Task('sleep', '5', function(JobResults $job) {
|
||||
echo "Task {$job->getId()} completed with data: {$job->getData()} \n";
|
||||
}));
|
||||
|
||||
|
||||
$client->addTask(new Task('sleep', '5', function(JobResults $job) {
|
||||
echo "Task {$job->getId()} completed with data: {$job->getData()} \n";
|
||||
}));
|
||||
|
||||
|
||||
$client->run();
|
15
tests/gearman_closure.php
Normal file
15
tests/gearman_closure.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
|
||||
use Tamer\Objects\JobResults;
|
||||
use Tamer\Objects\Task;
|
||||
|
||||
import('net.nosial.tamerlib', 'latest');
|
||||
|
||||
$client = new \Tamer\Protocols\GearmanClient();
|
||||
$client->addServer();
|
||||
|
||||
$client->closure(function () {
|
||||
echo "This function was sent from a client, it should be executed on the worker";
|
||||
});
|
|
@ -1,17 +1,21 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
use Tamer\Objects\Task;
|
||||
|
||||
use Tamer\Objects\Job;
|
||||
|
||||
import('net.nosial.tamerlib', 'latest');
|
||||
$worker = new \Tamer\Protocols\GearmanWorker();
|
||||
$worker->addServer();
|
||||
|
||||
$worker->addFunction('sleep', function($task) {
|
||||
var_dump(get_class($task));
|
||||
echo "Task {$task->getId()} started with data: {$task->getData()} \n";
|
||||
sleep($task->getData());
|
||||
echo "Task {$task->getId()} completed with data: {$task->getData()} \n";
|
||||
$worker->addFunction('sleep', function($job) {
|
||||
/** @var Job $job */
|
||||
var_dump(get_class($job));
|
||||
echo "Task {$job->getId()} started with data: {$job->getData()} \n";
|
||||
sleep($job->getData());
|
||||
echo "Task {$job->getId()} completed with data: {$job->getData()} \n";
|
||||
|
||||
return $job->getData();
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue