调度协程任务（请求）

@param Task $task 协程实例
@param callable|null $callback 特殊场景回调，如清理资源
@return $this
352279
public function schedule(Task $task, callable $callback = null)
    {
        // 特殊场景回调，如清理资源
        if ($callback !== null) {
            $task->resetCallBack($callback);
        }

        /* @var $task Task */
        $task->run();

        try {
            do {
                // 迭代器检查
                if (!$task->getRoutine() instanceof \Generator) {
                    break;
                }

                // 协程异步IO
                if ($task->getRoutine()->valid() && ($task->getRoutine()->current() instanceof IBase)) {
                    break;
                }

                // 继续调度
                if (!$task->isFinished()) {
                    $this->schedule($task);
                    break;
                }

                // 请求调度结束（考虑是否回调）
                $task->resetRoutine();
                if (is_callable($task->getCallBack())) {
                    $func = $task->getCallBack();
                    $task->resetCallBack();
                    $func();
                    break;
                }
            } while (0);
        } catch (\Throwable $e) {
            $task->handleTaskException($e, null);
            $this->schedule($task);
        }

        return $this;
    }
509673
public function dispatch(\Closure $task, $middlewares = null)
    {
        is_array($middlewares) || $middlewares = $this->getMiddlewares();

        $beforeReturnValue = $this->before($middlewares);

        if ($beforeReturnValue === false || $beforeReturnValue !== true) {
            return $beforeReturnValue;
        }

        $this->setPayload($task());

        $afterReturnValue = $this->after(array_reverse($middlewares));

        if ($afterReturnValue === false || $afterReturnValue !== true) {
            return $afterReturnValue;
        }

        return $this->getPayload();
    }
393917
public function bindCallback(Closure $callback, $query = null) {
        call_user_func_array($callback, [$this, $query]);

        return $this;
    }
252072
public function endTask(Task $task)
    {
        if ($task->isShallow()) {
            return;
        }

        $endTime = round(microtime(true) * 1000);
        $millis = $endTime - $this->startTime;
        $seconds = floor($millis / 1000);
        $millis = $millis - $seconds * 1000;
        $taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms";

        $shouldReplaceTaskMark =
            $this->output->isDecorated() &&
            $this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL &&
            !$this->output->getWasWritten();

        if ($shouldReplaceTaskMark) {
            $this->output->writeln("\r\033[K\033[1A\r<info>✔</info>");
        } else {
            if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) {
                $this->output->writeln("<info>✔</info> Ok");
            } else {
                $this->output->writeln("<info>✔</info> Ok [$taskTime]");
            }
        }
    }
1119186
public function first(callable $callback = null)
    {
        if (null === $callback) {
            return reset($this->items);
        }

        return $this->filter($callback)->first();
    }
646066
public function forkTask(Task $task)
    {
        $cronExpression = $task->getCronExpression();
        if (true === $cronExpression->isDue()) {
            $this->getLogger()->info(
                sprintf('Starting cron task "%s"', $task->getName()),
                array(
                    'command' => $task->getCommandToExecute()
                )
            );
            $taskProcess = new Process($task->getCommandToExecute());
            $taskProcess->start();
        }
    }
1214005
public function when($value, $callback, $default = null)
    {
        if ($value) {
            return $callback($this, $value) ?: $this;
        } elseif ($default) {
            return $default($this, $value) ?: $this;
        }

        return $this;
    }
262349
public function create(Task $task): Task
    {
        $response = $this->client->post($this->prepareUrlForKey('add-task'), [], $task->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Task($responseData);
    }
561933
public function addTask(Task $t)
    {
        if ($this->nestedTask !== null) {
            throw new BuildException(
                'The retry task container accepts a single nested task'
                . ' (which may be a sequential task container)'
            );
        }
        $this->nestedTask = $t;
    }
310254
protected function passToRemoteProcessor(Task $task)
    {
        return $this->getRemoteProcessor($task)->run($task, function ($type, $host, $line) {
            if (starts_with($line, 'Warning: Permanently added ')) {
                return;
            }

            $this->displayOutput($type, $host, $line);
        });
    }
2580
public function sort(callable $callback = null) : Stack
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }
92950
public function each(callable $callback = null)
	{
		foreach($this->list as $item)
		{
			if(call_user_func($callback, $item) === false)
				return $this;
		}
		
		return $this;
	}
133327
protected function runTask($container, $task)
    {
        $macroOptions = $container->getMacroOptions($this->argument('task'));

        $confirm = $container->getTask($task, $macroOptions)->confirm;

        if ($confirm && ! $this->confirmTaskWithUser($task, $confirm)) {
            return;
        }

        if (($exitCode = $this->runTaskOverSSH($container->getTask($task, $macroOptions))) > 0) {
            foreach ($container->getErrorCallbacks() as $callback) {
                call_user_func($callback, $task);
            }

            return $exitCode;
        }

        foreach ($container->getAfterCallbacks() as $callback) {
            call_user_func($callback, $task);
        }
    }
147727
public function update(Task $task): Task
    {
        $id = $task->getId();

        $task->setId(null);

        $response = $this->client->put($this->prepareUrlForKey('update-task', ['id' => $id]), [], $task->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Task($responseData);
    }
626962
public function delete(Task $task)
    {
        $this->om->remove($task);
        $this->om->flush();

        $this->notify(NotifierInterface::MESSAGE_DELETE);
    }
321117
public function sort(callable $callback = null) : Queue
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }
843747
public function on($target, $event, $callback = null)
    {
        $echostr        = isset($_GET['echostr']) ? $_GET['echostr'] : null;
        $checkSignature = $this->checkSignature();

        if (!$checkSignature) {
            exit("签名验证失败");
        }

        if (!empty($echostr)) {
            echo $echostr;
            exit;
        }

        if (is_null($callback)) {
            $callback = $event;
            $event    = '*';
        }

        if (!is_callable($callback)) {
            exit("$callback 不是一个可调用的函数或方法");
        }

        $rest = $this->$target($event);

        $datas         = [];
        $datas['data'] = $rest;

        if (!empty($rest)) {
            $rest_user                 = [];
            $rest_user['ToUserName']   = $rest['FromUserName'];
            $rest_user['FromUserName'] = $rest['ToUserName'];
            $rest_msg                  = call_user_func_array($callback, $datas);

            if ($rest_msg == 'success') {
                exit('success');
            }

            $rest_array = array_merge($rest_user, $rest_msg);

            $rest_xml = $this->arrayToXml($rest_array);

            $msg_signature = isset($_GET['msg_signature']) ? $_GET['msg_signature'] : null;
            if (!empty($msg_signature) && $msg_signature != '') {
                $rest_xml = $this->encryptMsg($rest_xml);
            }

            exit($rest_xml);
        } else {
            return false;
        }
    }