mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-22 11:58:55 +00:00
121 lines
2.8 KiB
XML
121 lines
2.8 KiB
XML
![]() |
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<!-- $Revision$ -->
|
||
|
|
||
|
<refentry xml:id="pht.thread.addFunctionTask" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||
|
<refnamediv>
|
||
|
<refname>Thread::addFunctionTask</refname>
|
||
|
<refpurpose>Function threading</refpurpose>
|
||
|
</refnamediv>
|
||
|
|
||
|
<refsect1 role="description">
|
||
|
&reftitle.description;
|
||
|
<methodsynopsis>
|
||
|
<modifier>public</modifier> <type>void</type><methodname>Thread::addFunctionTask</methodname>
|
||
|
<methodparam><type>callable</type><parameter>func</parameter></methodparam>
|
||
|
<methodparam choice="opt"><type>mixed</type><parameter>...funcArgs</parameter></methodparam>
|
||
|
</methodsynopsis>
|
||
|
<para>
|
||
|
Adds a new function task to a <classname>Thread</classname>s internal task queue.
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="parameters">
|
||
|
&reftitle.parameters;
|
||
|
<variablelist>
|
||
|
<varlistentry>
|
||
|
<term><parameter>func</parameter></term>
|
||
|
<listitem>
|
||
|
<para>
|
||
|
The function to be threaded. If it is bound to an instance, then
|
||
|
<literal>$this</literal> will become &null;.
|
||
|
</para>
|
||
|
</listitem>
|
||
|
</varlistentry>
|
||
|
<varlistentry>
|
||
|
<term><parameter>...funcArgs</parameter></term>
|
||
|
<listitem>
|
||
|
<para>
|
||
|
An optional list of arguments for the function. These arguments will be
|
||
|
serialised (since they are being passed to another thread).
|
||
|
</para>
|
||
|
</listitem>
|
||
|
</varlistentry>
|
||
|
</variablelist>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="returnvalues">
|
||
|
&reftitle.returnvalues;
|
||
|
<para>
|
||
|
No return value.
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
|
||
|
<refsect1 role="examples">
|
||
|
&reftitle.examples;
|
||
|
<para>
|
||
|
<example>
|
||
|
<title>Adding a new function task to a thread</title>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?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();
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
&example.outputs;
|
||
|
<screen>
|
||
|
<![CDATA[
|
||
|
int(1)
|
||
|
int(2)
|
||
|
int(3)
|
||
|
int(4)
|
||
|
int(5)
|
||
|
int(6)
|
||
|
]]>
|
||
|
</screen>
|
||
|
</example>
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
</refentry>
|
||
|
|
||
|
<!-- Keep this comment at the end of the file
|
||
|
Local variables:
|
||
|
mode: sgml
|
||
|
sgml-omittag:t
|
||
|
sgml-shorttag:t
|
||
|
sgml-minimize-attributes:nil
|
||
|
sgml-always-quote-attributes:t
|
||
|
sgml-indent-step:1
|
||
|
sgml-indent-data:t
|
||
|
indent-tabs-mode:nil
|
||
|
sgml-parent-document:nil
|
||
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||
|
sgml-exposed-tags:nil
|
||
|
sgml-local-catalogs:nil
|
||
|
sgml-local-ecat-files:nil
|
||
|
End:
|
||
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
|
vim: et tw=78 syn=sgml
|
||
|
vi: ts=1 sw=1
|
||
|
-->
|