@leec
實現這個代表dispatch後會放入Queue(根據你config/queue.php裡面的設定,例如redis)裡面等待排序執行,也就是異步(Async)
執行
下面是框架源碼:
/**
* Dispatch a command to its appropriate handler.
*
* @param mixed $command
* @return mixed
*/
public function dispatch($command)
{
if ($this->queueResolver && $this->commandShouldBeQueued($command)) {
return $this->dispatchToQueue($command);
} else {
return $this->dispatchNow($command);
}
}
/**
* Dispatch a command to its appropriate handler in the current process.
*
* @param mixed $command
* @return mixed
*/
public function dispatchNow($command)
{
return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) {
return $this->container->call([$command, 'handle']);
});
}
/**
* Determine if the given command should be queued.
*
* @param mixed $command
* @return bool
*/
protected function commandShouldBeQueued($command)
{
return $command instanceof ShouldQueue;
}
可以很明顯看他會檢查是否有實現ShouldQueue
有 -> 丟入Queue中
沒有 -> 直接 call handle方法
至於為什麼會返回0,似乎是你queue沒設定,導致他push進去queue時失敗,所以返回個0