Skip to content

Commit

Permalink
Fixed some issues with stub method signatures
Browse files Browse the repository at this point in the history
This updates the stub to match pthreads v3 properly, as per the arginfo of the extension. Some issues were discovered in the process (see #835 and #836), so method signatures have been adjusted to match the documentation where there are mismatches.

The formatting in this file is very inconsistent, I went to great pains to avoid reformatting it to avoid polluting the diff.
  • Loading branch information
dktapps committed Feb 21, 2018
1 parent 2bc4406 commit 7174128
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions examples/stub.php
Expand Up @@ -3,7 +3,7 @@
* pthreads extension stub file for code completion purposes
*
* @author Lisachenko Alexander <lisachenko.it@gmail.com>
* @version 2.0.0
* @version 3.0.0
*/

/**
Expand Down Expand Up @@ -74,11 +74,12 @@ public function addRef() {}
* Fetches a chunk of the objects properties table of the given size
*
* @param int $size The number of items to fetch
* @param bool $preserve Preserve the keys of members
*
* @link http://www.php.net/manual/en/threaded.chunk.php
* @return array An array of items from the objects member table
*/
public function chunk($size) {}
public function chunk($size, $preserve = false) {}

/**
* {@inheritdoc}
Expand Down Expand Up @@ -110,7 +111,7 @@ public function getRefCount() {}
*
* @return bool(true) The referenced object can be destroyed
*/
public function isGarbage() {}
public function isGarbage() : bool{}

/**
* Tell if the referenced object is executing
Expand All @@ -132,7 +133,7 @@ public function isTerminated() {}
* Merges data into the current object
*
* @param mixed $from The data to merge
* @param bool $overwrite Overwrite existing keys flag, by default true
* @param bool $overwrite Overwrite existing keys flag
*
* @link http://www.php.net/manual/en/threaded.merge.php
* @return bool A boolean indication of success
Expand Down Expand Up @@ -207,7 +208,7 @@ public function shift() {}
* @link http://www.php.net/manual/en/threaded.synchronized.php
* @return mixed The return value from the block
*/
public function synchronized(\Closure $function, $args = null) {}
public function synchronized(\Closure $function, ...$args) {}

/**
* Waits for notification from the Stackable
Expand All @@ -217,7 +218,7 @@ public function synchronized(\Closure $function, $args = null) {}
* @link http://www.php.net/manual/en/threaded.wait.php
* @return bool A boolean indication of success
*/
public function wait($timeout = 0) {}
public function wait(int $timeout = 0) {}
}

/**
Expand All @@ -243,7 +244,6 @@ class Volatile extends Threaded{
*/
class Thread extends Threaded
{

/**
* Will return the identity of the Thread that created the referenced Thread
*
Expand Down Expand Up @@ -307,7 +307,7 @@ public function join() {}
* @link http://www.php.net/manual/en/thread.start.php
* @return bool A boolean indication of success
*/
public function start($options = PTHREADS_INHERIT_ALL) {}
public function start(int $options = PTHREADS_INHERIT_ALL) {}
}

/**
Expand All @@ -327,22 +327,21 @@ public function start($options = PTHREADS_INHERIT_ALL) {}
*/
class Worker extends Thread
{

/**
* Executes the optional collector on each of the tasks, removing the task if true is returned
*
* @param callable $collector The collector to be executed upon each task
* @param callable $function The collector to be executed upon each task
* @return int The number of tasks left to be collected
*/
public function collect($collector = null) {}
public function collect(callable $function = null) {}

/**
* Executes the collector on the collectable object passed
*
* @param callable $collectable The collectable object to run the collector on
* @param Collectable $collectable The collectable object to run the collector on
* @return bool The referenced object can be destroyed
*/
public function collector($collectable) {}
public function collector(Collectable $collectable) {}

/**
* Returns the number of threaded tasks waiting to be executed by the referenced Worker
Expand Down Expand Up @@ -376,17 +375,15 @@ public function shutdown() {}
* @link http://www.php.net/manual/en/worker.stack.php
* @return int The new length of the stack
*/
public function stack(Threaded &$work) {}
public function stack(Threaded $work) {}

/**
* Removes the referenced object ( or all objects if parameter is null ) from stack of the referenced Worker
*
* @param Threaded $work Threaded object previously stacked onto Worker
* Removes the first task (the oldest one) in the stack.
*
* @link http://www.php.net/manual/en/worker.unstack.php
* @return int The new length of the stack
* @return Collectable|null The item removed from the stack
*/
public function unstack(Threaded &$work = null) {}
public function unstack() {}
}

/**
Expand Down Expand Up @@ -444,14 +441,7 @@ class Pool
*
* @link http://www.php.net/manual/en/pool.__construct.php
*/
public function __construct($size, $class, array $ctor = array()) {}

/**
* Shuts down all Workers, and collect all Stackables, finally destroys the Pool
*
* @link http://www.php.net/manual/en/pool.__destruct.php
*/
public function __destruct() {}
public function __construct(int $size, string $class = Worker::class, array $ctor = array()) {}

/**
* Collect references to completed tasks
Expand All @@ -471,7 +461,7 @@ public function collect(callable $collector) {}
*
* @link http://www.php.net/manual/en/pool.resize.php
*/
public function resize($size) {}
public function resize(int $size) {}

/**
* Shutdown all Workers in this Pool
Expand All @@ -497,7 +487,7 @@ public function submit(Threaded $task) {}
*
* @return int the identifier of the Worker that accepted the object
*/
public function submitTo($worker, Threaded $task) {}
public function submitTo(int $worker, Threaded $task) {}
}

/**
Expand Down

0 comments on commit 7174128

Please sign in to comment.