Skip to content

Commit

Permalink
Use action object as job handler
Browse files Browse the repository at this point in the history
See #28
  • Loading branch information
lorisleiva committed Nov 15, 2019
1 parent dc8d1ac commit 7075572
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/BusDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

class BusDispatcher extends IlluminateDispatcher
{
public function getCommandHandler($command)
public function dispatchNow($command, $handler = null)
{
if ($command instanceof Action) {
return new class() {
public function handle($action)
{
return $action->runAsJob();
}
};
if (! $command instanceof Action) {
return parent::dispatchNow($command, $handler);
}

return parent::getCommandHandler($command);
$callback = function ($command) {
return $this->container->call([$command, 'runAsJob']);
};

return $this->pipeline->send($command)->through($this->pipes)->then($callback);
}
}

0 comments on commit 7075572

Please sign in to comment.