- if (count($this->__client)) {
- if ($this->__client->once()) {
- if ($timeout) {
- $timeout = $timeout($this);
- }
-
- $this->__log->debug(__FUNCTION__.": wait", compact("timeout"));
-
- $this->__client->wait($timeout);
- return 0 < count($this->__client);
- }
+ $invoker = new API\Invoker($this->__client);
+
+ if ($cbg instanceof \Generator) {
+ return $invoker->iterate($cbg)->promise();
+ }
+
+ if (is_callable($cbg)) {
+ return $invoker->invoke(function() use($cbg) {
+ return $cbg($this);
+ })->promise();