pht\Thread::addFunctionTask

(PECL pht >= 0.0.1)

pht\Thread::addFunctionTaskFunction threading

Descrição

public pht\Thread::addFunctionTask ( callable $func [, mixed $...funcArgs ] ) : void

Adds a new function task to a pht\Threads internal task queue.

Parâmetros

func

The function to be threaded. If it is bound to an instance, then $this will become NULL.

...funcArgs

An optional list of arguments for the function. These arguments will be serialised (since they are being passed to another thread).

Valor Retornado

No return value.

Exemplos

Exemplo #1 Adding a new function task to a thread

<?php

use pht\Thread;

class 
Test
{
    public static function 
run(){var_dump(5);}
    public static function 
run2(){var_dump(6);}
}

function 
aFunc(){var_dump(3);}

$thread = new Thread();

$thread->addFunctionTask(static function($one) {var_dump($one);}, 1);
$thread->addFunctionTask(function() {var_dump(2);});
$thread->addFunctionTask('aFunc');
$thread->addFunctionTask('array_map', function ($n) {var_dump($n);}, [4]);
$thread->addFunctionTask(['Test''run']);
$thread->addFunctionTask([new Test'run2']);

$thread->start();
$thread->join();

O exemplo acima irá imprimir:

int(1)
int(2)
int(3)
int(4)
int(5)
int(6)