GoLang pht\Thread::addClassTask

request it (296)
GoLang replacement for PHP's pht\Thread::addClassTask [edit | history]



Do you know a GoLang replacement for PHP's pht\Thread::addClassTask? Write it!

PHP pht\Thread::addClassTask

PHP original manual for pht\Thread::addClassTask [ show | php.net ]

pht\Thread::addClassTask

(PECL pht >= 0.0.1)

pht\Thread::addClassTaskClass threading

Description

public void pht\Thread::addClassTask ( string $className [, mixed $...ctorArgs ] )

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

Parameters

className

The name of the class to be threaded. This class must implement the pht\Runnable interface.

...ctorArgs

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

Return Values

No return value.

Examples

Example #1 Adding a new class task to a thread

<?php

use pht\{ThreadRunnable};

class 
Task implements Runnable
{
    private 
$one;

    public function 
__construct(int $one)
    {
        
$this->one $one;
    }

    public function 
run()
    {
        
var_dump($this->one);
    }
}

$thread = new Thread();

$thread->addClassTask(Task::class, 1);

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

The above example will output:

int(1)