Skip to content

[5.6] Add dispatchNow to Dispatchable Trait. - #23399

Merged
taylorotwell merged 1 commit into
laravel:5.6from
jrseliga:dispatch-now-dispatchable
Mar 6, 2018
Merged

[5.6] Add dispatchNow to Dispatchable Trait.#23399
taylorotwell merged 1 commit into
laravel:5.6from
jrseliga:dispatch-now-dispatchable

Conversation

@jrseliga

@jrseliga jrseliga commented Mar 6, 2018

Copy link
Copy Markdown
Contributor

@taylorotwell I wasn't sure if tests were necessary, as BusDispatcherTest@testDispatchNowShouldNeverQueue seems to cover this.

@devcircus

Copy link
Copy Markdown
Contributor

the dispatch method, in Dispatchable, defers to dispatchNow if the job isn't queued.

@jrseliga

jrseliga commented Mar 6, 2018

Copy link
Copy Markdown
Contributor Author

@devcircus I was under the same impression based on information I found on stackoverflow and Laracasts forum.

I see the dispatchNow fallback behavior on Dispatcher@dispatch, however, executing a Job from within a Controller for example, that is meant to perform an action and return data back synchronously is actually returned with an instance of PendingDispatch

Perhaps I've just missed something obvious?

dispatch-now

@devcircus

Copy link
Copy Markdown
Contributor

Ahh yes for Dispatchable, that is true. The DispatchesJobs trait is included by default in the base controller and has both "dispatch" and "dispatchNow".
Also, I tested on a project I'm working on and had forgotten I had made a custom dispatch method that handled async and sync jobs.

@jrseliga jrseliga changed the title Add dispatchNow to Dispatchable Trait. [5.6] Add dispatchNow to Dispatchable Trait. Mar 6, 2018
@taylorotwell
taylorotwell merged commit ab526b7 into laravel:5.6 Mar 6, 2018
@jrseliga
jrseliga deleted the dispatch-now-dispatchable branch March 7, 2018 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants