Utility method to await for an Operation finishes.

@param Operation $operation The Operation object to await for
@param int       $interval

@return Operation
503616
public function awaitOperation(Operation $operation, $interval = 5)
    {
        while ($operation->getState() == OperationState::InProgress) {
            $operation = $this->getOperation($operation);
            if ($operation->getState() == OperationState::InProgress) {
                sleep($interval);
            }
        }

        return $operation;
    }
1084132
public function find(string $operation, string $locale)
    {
        $model = $this->notifications->first(function ($value) use($operation, $locale) {
            return $value->code === $locale && ($value->title === $operation || $value->name === $operation);
        });

        return $model ? $model->content : false;
    }
116536
public function execute(string $type, string $operation, array $parameters = [])
    {
        return $this->{$type}->{$operation}(...$parameters);
    }
560886
public function execute(RiakOperation $operation)
    {
        if (empty($this->nodes)) {
            throw new RiakException('There are no nodes in the cluster.');
        }

        $size  = count($this->nodes);
        $index = mt_rand(0, $size - 1);
        $node  = $this->nodes[$index];

        return $node->execute($operation);
    }
874805
public static OperationState await(MediaContract service, String operationId) throws ServiceException {
        if (operationId == null) {
            return OperationState.Succeeded;
        }
        OperationInfo opinfo;
        do {
            opinfo = service.get(Operation.get(operationId));            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // intentionally do nothing
            }
        } while (opinfo.getState().equals(OperationState.InProgress));
        return opinfo.getState();
    }
839081
public function setCanResendAfter($interval)
    {
        $key = $this->generateKey(self::CAN_RESEND_UNTIL_KEY);
        $time = time() + intval($interval);
        self::storage()->set($key, $time);
    }
1118436
public function wait($block = false, $interval = 100)
    {
        do {
            if ($this->isFinished()) {
                return;
            }
            parent::wait(false);
            if ($this->aliveCount() < $this->max) {
                foreach ($this->processes as $process) {
                    if ($process->isStarted()) continue;
                    $process->start();
                    if ($this->aliveCount() >= $this->max) break;
                }
            }
            $block ? usleep($interval) : null;
        } while ($block);
    }
172023
public function stream_lock(int $operation): bool
    {
        if ((LOCK_NB & $operation) == LOCK_NB) {
            $operation = $operation - LOCK_NB;
        }

        return $this->content->lock($this, $operation);
    }
1087617
final public static function recalculateInterval($interval)
    {
        try {
            $from = new \DateTimeImmutable();
            $to = $from->add($interval);
            $diff = $to->diff($from);
            foreach ($diff as $k => $v) {
                $interval->$k = $v;
            }

        } catch (\Exception $e) {
        }

        return $interval;
    }
1185108
public CompletableFuture<byte[]> invoke(PrimitiveOperation operation) {
    CompletableFuture<byte[]> future = new CompletableFuture<>();
    switch (operation.id().type()) {
      case COMMAND:
        context.execute(() -> invokeCommand(operation, future));
        break;
      case QUERY:
        context.execute(() -> invokeQuery(operation, future));
        break;
      default:
        throw new IllegalArgumentException("Unknown operation type " + operation.id().type());
    }
    return future;
  }
648952
public function work($interval = self::DEFAULT_INTERVAL, $blocking = false)
    {
        if ($interval !== null) {
            $this->interval = $interval;
        }

        $this->updateProcLine('Starting');
        $this->startup();

        while (true) {
            if (function_exists('pcntl_signal_dispatch')) {
                pcntl_signal_dispatch();
            }
            if ($this->shutdown) {
                break;
            }
            if (!$this->paused) {
                /** Handle delayed items for the next scheduled timestamp. */
                $this->handleDelayedItems(null);
            } else {
                $this->updateProcLine('Paused');
            }
            $this->updateProcLine('Waiting for new jobs');
            sleep($this->interval);
        }

        $this->unregisterWorker();
    }
221454
public function watch($command, $interval = 500)
    {
        $count = 0;
        $activeTime = time();
        $maxTime = (int)$this->config['max_watch_time'];
        $intervalUs = $interval * 1000;

        //echo "watch command: $command, refresh interval: {$interval}ms\n";

        while (true) {
            $count++;
            $result = $this->command($command);

            if (0 === strpos($result, 'ERR')) {
                echo "$result\n";
                echo "error command: $command. ";
                break;
            }

            // clear screen before output
            echo "\033[2JThe {$count} times watch {$command} result(refresh interval: {$interval}ms):\n{$result}\n";

            if ($maxTime > 0 && time() - $activeTime >= $maxTime) {
                echo 'watch time end. ';
                break;
            }

            usleep($intervalUs);
        }

        echo "Quit\n";
    }
828035
public function remove(OperationState $operation = NULL)
    {
        if (is_null($operation)) {
            array_pop($this->operationQueue);
            return TRUE;
        } else {
            if ($this->isInQueue($operation)) {
                unset($this->operationQueue[$operation->getKey()]);
                return TRUE;
            }
            return FALSE;
        }
    }
341694
public function changeInterval($id, $interval) {
        return $this->webService->post("UPDATE 'PUSH'.'PUSHINTERVAL'", [
            self::PARAMETER_PUSH_ID => $id,
            self::PARAMETER_PUSH_INTERVAL => $interval
        ]);
    }
1350176
public function addOperation(OperationInterface $operation)
    {
        if (!$this->operations->contains($operation)) {
            $this->operations->add($operation);
        }

        return $this;
    }
77193
public static function range(float $start, float $end, float $interval = 1.) : self
    {
        if ($interval <= 0.) {
            throw new InvalidArgumentException('Interval must be greater'
                 . " than 0, $interval given.");
        }

        return static::quick(range($start, $end, $interval));
    }
1145909
public function process($src, OperationInterface $operation)
    {
        $argument = $operation->getValue();
        $operator = $operation->getOperator();
        $field = $operation->getField();
        switch ($operator) {
            case FilterOperation::OPERATOR_STR_STARTS_WITH:
                $operator = FilterOperation::OPERATOR_LIKE;
                $argument .= '%';
                break;
            case FilterOperation::OPERATOR_STR_ENDS_WITH:
                $operator = FilterOperation::OPERATOR_LIKE;
                $argument = '%' . $argument;
                break;
            case FilterOperation::OPERATOR_STR_CONTAINS:
                $operator = FilterOperation::OPERATOR_LIKE;
                $argument = '%' . $argument . '%';
                break;
        }
        $src->conditions[]  = "$field $operator :$field";
        $src->bindings[':' . $field] = $argument;
        return $src;
    }