Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide guidance on when to use Messages vs Tasks #1070

Merged
merged 8 commits into from
Sep 13, 2018

Conversation

Crell
Copy link
Contributor

@Crell Crell commented Sep 6, 2018

No description provided.

| Must be serializable | May be serializable
| May be delayed | Must be processed immediately
| Listener order not guaranteed | Listener order is guaranteed
| All listeners will fire | Listeners may short-circuit the pipeline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May short-circuit the pipeline IF AND ONLY IF the stoppable task interface was used for the task provided.

@Crell Crell changed the title Add table of Message vs Task differences. Provide guidance on when to use Messages vs Tasks Sep 6, 2018

A Task Processor is appropriate when:

* The event is being used as a "hook" or "pointcut" to extent or modify the Emitter's behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend


* The event is being used as a "hook" or "pointcut" to extent or modify the Emitter's behavior.
* The Emitter wishes to allow listeners to interact with each other (through mutating the event).
* NEED A 3RD EXAMPLE HERE.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe... those first two (especially the first) were great.

Copy link
Contributor Author

@Crell Crell Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but IMO we should have 3 for each, to make it clear that they're both legit. 😄 I like parallelism.


* The event is being used as a "hook" or "pointcut" to extend or modify the Emitter's behavior.
* The Emitter wishes to allow listeners to interact with each other (through mutating the event).
* NEED A 3RD EXAMPLE HERE.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: "The emitter chooses to delegate when processing is complete to the listeners."


| Messages | Tasks
|-------------------------------|-------------------------------
| Must be immutable | May me mutable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/me/be/

|-------------------------------|-------------------------------
| Must be immutable | May me mutable
| Must be serializable | May be serializable
| May be delayed | Must be processed immediately
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely convinced that tasks must be processed immediately. As @WyriHaximus demonstrated last week, a Task could compose one or more promises, which the listeners either create or react to. As such, processing could be delayed in them as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True; although in that case I would argue that the listener is processing the event by enqueuing the async action.

Perhaps "listeners must be called immediately" (even if the listener then does something async)?

| Must be immutable | May me mutable
| Must be serializable | May be serializable
| May be delayed | Must be processed immediately
| Listener order not guaranteed | Listener order is guaranteed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listener order is a product of the listener provider, not the notifier or the task processor; they simply iterate the listeners. As such, I'm not sure we should bring it up here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A notifier may do something like fork or use pthreads to handle different listeners, which means the order is non-deterministic. Task order must be determinstic.


As a general guideline, a Message Notifier is appropriate when:

* The Emitter does not care what responses are taken to an event.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rephrase this to:

The Emitter does not care what actions listeners take in response to an event.

Unless this is implying the emitter does not check the event state on each iteration. In which case:

The Emitter will not check event state after each listener.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means both; it doesn't care and it won't check. I've changed it to your first suggestion.

@WyriHaximus WyriHaximus merged commit c3e252e into php-fig:master Sep 13, 2018
@Crell Crell deleted the psr-14-distinctions branch September 13, 2018 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants