Changeset View
Changeset View
Standalone View
Standalone View
src/future/FutureIterator.php
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | /* -( Configuring Iteration )---------------------------------------------- */ | ||||
/** | /** | ||||
* Set a maximum amount of time you want to wait before the iterator will | * Set a maximum amount of time you want to wait before the iterator will | ||||
* yield a result. If no future has resolved yet, the iterator will yield | * yield a result. If no future has resolved yet, the iterator will yield | ||||
* null for key and value. Among other potential uses, you can use this to | * null for key and value. Among other potential uses, you can use this to | ||||
* show some busy indicator: | * show some busy indicator: | ||||
* | * | ||||
* $futures = id(new FutureIterator($futures)) | * $futures = (new FutureIterator($futures)) | ||||
* ->setUpdateInterval(1); | * ->setUpdateInterval(1); | ||||
* foreach ($futures as $future) { | * foreach ($futures as $future) { | ||||
* if ($future === null) { | * if ($future === null) { | ||||
* echo "Still working...\n"; | * echo "Still working...\n"; | ||||
* } else { | * } else { | ||||
* // ... | * // ... | ||||
* } | * } | ||||
* } | * } | ||||
Show All 11 Lines | public function setUpdateInterval($interval) { | ||||
$this->timeout = $interval; | $this->timeout = $interval; | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* Limit the number of simultaneously executing futures. | * Limit the number of simultaneously executing futures. | ||||
* | * | ||||
* $futures = id(new FutureIterator($futures)) | * $futures = (new FutureIterator($futures)) | ||||
* ->limit(4); | * ->limit(4); | ||||
* foreach ($futures as $future) { | * foreach ($futures as $future) { | ||||
* // Run no more than 4 futures simultaneously. | * // Run no more than 4 futures simultaneously. | ||||
* } | * } | ||||
* | * | ||||
* @param int Maximum number of simultaneous jobs allowed. | * @param int Maximum number of simultaneous jobs allowed. | ||||
* @return this | * @return this | ||||
* | * | ||||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0