note 116410 added to pool.collect
| From: | your dot brother dot t at hotmail dot com | Date: | Mon, 29 Dec 2014 09:33:18 +0000 |
| Subject: | note 116410 added to pool.collect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201273@lists.php.net to get a copy of this message | ||
The example code crashes and made me waste 2 working days
First of all,
Stackable has no attribute named $worker or it's access method made
it inaccessible.
Secondly, Stackable also doesn't have getThreadId() . It's best
practice to use Thread class for realization of a thread since it has more control
functions. It's better to use Stackable for object storage and use it's
run() as its initialization.
The working example is
<?php
class MyWork extends Thread {
protected $complete;
public function __construct() {
$this->complete = false;
}
public function run() {
printf(
"Hello from %s in Thread #%lu\n",
__CLASS__, $this->getThreadId());
$this->complete = true;
}
public function isComplete() {
return $this->complete;
}
}
class Something {}
class MyWorker extends Worker {
public function __construct(Something $something) {
$this->something = $something;
}
public function run() {
/** ... **/
}
}
$pool = new Pool(8, \MyWorker::class, [new Something()]);
$pool->submit(new MyWork());
usleep(1000);
$pool->collect(function($work){
return $work->isComplete();
});
var_dump($pool);
?>
----
Server IP: 92.48.119.85
Probable Submitter: 77.237.91.220
----
Manual Page -- http://php.net/manual/en/pool.collect.php
Edit -- https://master.php.net/note/edit/116410
Del: integrated -- https://master.php.net/note/delete/116410/integrated
Del: useless -- https://master.php.net/note/delete/116410/useless
Del: bad code -- https://master.php.net/note/delete/116410/bad+code
Del: spam -- https://master.php.net/note/delete/116410/spam
Del: non-english -- https://master.php.net/note/delete/116410/non-english
Del: in docs -- https://master.php.net/note/delete/116410/in+docs
Del: other reasons-- https://master.php.net/note/delete/116410
Reject -- https://master.php.net/note/reject/116410
Search -- https://master.php.net/manage/user-notes.php