Skip to content

Remove nextTick() and NextTickQueue #30

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

Merged
merged 2 commits into from
Feb 8, 2017

Conversation

clue
Copy link
Member

@clue clue commented Jun 7, 2015

This PR is a RFC – any input is welcome.

v0.4 introduced both "future ticks" and "next ticks".

This PR aims to serve as a discussion basis whether it actually makes sense to keep both.

Edit: This PR removes the nextTick() method and its underlying NextTickQueue implementation. Use the futureTick() method instead.

@clue
Copy link
Member Author

clue commented Sep 16, 2015

For the reference, both queues have been implemented by @jmalloc via reactphp/reactphp#234 and reactphp/reactphp#249 respectively. Let's ping @jmalloc, perhaps you can share your view on this?

The latter also has some discussion on this:

here's probably some discussion to be had about how necessary this is. I think it is necessary, as without it there is no way to execute user code on each tick of the engine without starving IO/timers (nextTick is too greedy).
The implementation is identical to nextTick, except that callbacks registered inside an existing futureTick handler will not be processed on the same tick. In other words, when the future-tick queue is processed, only the callbacks that were already on the queue are executed. With this implementation, futureTick should generally be favoured over nextTick unless you specifically need the stricter guarantees of nextTick.

Long story short, cooperative multitasking will likely depend on futureTick() instead of nextTick().

There's also some confusion about this topic in #28.

I'm still curious if we have a valid use case for nextTick(), i.e. explicitly starving the event loop if we repeatedly add events to the loop. Otherwise, I'd suggest removing the nextTick() method as per this PR.

For what it's worth, nodejs also has:

@clue
Copy link
Member Author

clue commented Sep 16, 2015

For what it's worth, nodejs also has:

Afaict there's also debate about which function should be used, e.g. see http://stackoverflow.com/a/15349865

I'm well aware of the differences between both functions. However, I have yet to find a valid use case for nextTick()

@WyriHaximus
Copy link
Member

👍 on removing next ticks, it just adds confusion without a real good use case for keeping them

@jmalloc
Copy link
Contributor

jmalloc commented Sep 17, 2015

I can't see any immediate reason to retain nextTick. For whatever it's worth, the only large project I have using React is Recoil and it does not use nextTick at all.

@jmalloc
Copy link
Contributor

jmalloc commented Sep 17, 2015

I'd also like to add that I was never quite happy with the name futureTick. Since this is a BC break anyway, maybe we could consider more appropriate names. $loop->defer($work); might make more sense?

@WyriHaximus
Copy link
Member

I'm with @jmalloc renaming futureTick to defer is a great idea 👍

@cboden
Copy link
Member

cboden commented Sep 17, 2015

I'm ok with renaming and defer makes sense grammatically, however I do worry about the confusion of the word. React also houses the Promise library where invoking a defer call created a deferred object that can resolve or reject a promise object.

@jmalloc
Copy link
Contributor

jmalloc commented Sep 18, 2015

That's a valid concern for sure. I still personally prefer defer, but offer enqueue as a possible alternative. At any rate, I think it should be a verb :)

@WyriHaximus WyriHaximus mentioned this pull request Sep 29, 2015
@nrk
Copy link
Member

nrk commented Oct 1, 2015

I'm with @cboden regarding the potential confusion of using defer but well that's actually what it does... maybe postpone? I do agree on the fact that the current futureTick and nextTick are awful names, after all we had the same discussion at the time of @jmalloc's PR from a while back and we couldn't come up with valid alternatives.

Back to the initial scope of this PR, I'm still torn about removing nextTick altogether but I don't have a strong and practical use case to support it.

@cboden
Copy link
Member

cboden commented Oct 1, 2015

Ye old thesaurus came up with a few options, my top ones:

  • delay
  • postpone
  • mothball

I agree that defer is grammatically correct but, to me, it's synonymous with containing a promise object - which is not the case in this context.

@WyriHaximus
Copy link
Member

WyriHaximus commented Oct 1, 2015 via email

@yriveiro
Copy link

yriveiro commented Oct 5, 2015

The term schedule seems good enough to understand that you're deferring the task to other loop iteration. With enqueue, you don't know if you are enqueuing for this loop iteration or not, It is not as explicit as schedule.

As a non experienced user of reactphp (I started to read the code last week), my first thought after read defer was: this return a promise?

@jsor
Copy link
Member

jsor commented Feb 3, 2017

👍 for removing nextTick. Also 👍 for renaming futureTick to defer.

@nrk
Copy link
Member

nrk commented Feb 3, 2017

I just noticed that I used nextTick only one time in predis\async to fix an issue but it's old stuff (and so damn un-Reacty anyway at this point) and I guess futureTick would've probably worked anyway. All in all I wouldn't mind having nextTick removed. As for futureTick, despite being an awful name I still have doubts about renaming it to defer.

@jsor
Copy link
Member

jsor commented Feb 3, 2017

Btw, the async-interop loop also uses defer: https://github.com/async-interop/event-loop/blob/master/src/Loop.php#L148

@clue
Copy link
Member Author

clue commented Feb 3, 2017

Technically, this PR is a BC break and if we are to accept this, this will be part of the upcoming v0.5 release.

However, I would vote for keeping the method names as-is for now at least. If we are to accept this PR, then we'll remove nextTick() and only futureTick() remains.

Empirical evidence seems to suggest that:

  • Most consumers of this lib don't use either
  • Those that actually use futureTick() could probably switch from nextTick() without affecting operation

This means that while this PR is a BC break, most consumers of this library are likely compatible with the current v0.4 as well as the upcoming v0.5 release.

I'm not saying futureTick(), defer() or anything else makes any more sense, but I'd vote to move this discussion to another release.

@jsor
Copy link
Member

jsor commented Feb 4, 2017

@clue Good point, agreed. 👍

Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

@jsor @clue agreed, lets tackle the name in a different PR 👍

@clue clue changed the title [RFC] Remove NextTickQueue Remove nextTick() and NextTickQueue Feb 6, 2017
@clue clue added this to the v0.5.0 milestone Feb 6, 2017
@WyriHaximus WyriHaximus merged commit 5979fc9 into reactphp:master Feb 8, 2017
@clue clue deleted the no-next-tick branch February 8, 2017 17:54
akemin-dayo added a commit to akemin-dayo/PHPCraft that referenced this pull request Dec 24, 2021
…her details are below. Also cleaned up composer.json so we don't import the entirety of ReactPHP, but rather only the parts we actually need.

The following changes were made to PHPCraft due to API changes and/or deprecations in ReactPHP:
・MultiplayerServer: [API breaking change as of 0.5.0] ReactPHP Socket listen() has been removed, with its functionality moved to the Server constructor. As such, the Server constructor format also changed, and its call location had to be moved in PHPCraft's code. — see https://github.com/reactphp/socket/releases/tag/v0.5.0
・MultiplayerServer, EntityManager: [API breaking change as of 0.5.0] ReactPHP EventLoop's nextTick() has been removed and replaced by futureTick() — see https://github.com/reactphp/event-loop/releases/tag/v0.5.0 and reactphp/event-loop#30
・MultiplayerServer: [API deprecation as of 1.2.0] ReactPHP EventLoop's Factory::create() has been deprecated and replaced by Loop::get() — see https://github.com/reactphp/event-loop/releases/tag/v1.2.0
akemin-dayo added a commit to akemin-dayo/PHPCraft that referenced this pull request Dec 25, 2021
…her details are below. Also cleaned up composer.json so we don't import the entirety of ReactPHP, but rather only the parts we actually need.

The following changes were made to PHPCraft due to API changes and/or deprecations in ReactPHP:
・MultiplayerServer: [API breaking change as of 0.5.0] ReactPHP Socket listen() has been removed, with its functionality moved to the Server constructor. As such, the Server constructor format also changed, and its call location had to be moved in PHPCraft's code. — see https://github.com/reactphp/socket/releases/tag/v0.5.0
・MultiplayerServer, EntityManager: [API breaking change as of 0.5.0] ReactPHP EventLoop's nextTick() has been removed and replaced by futureTick() — see https://github.com/reactphp/event-loop/releases/tag/v0.5.0 and reactphp/event-loop#30
・MultiplayerServer: [API deprecation as of 1.2.0] ReactPHP EventLoop's Factory::create() has been deprecated and replaced by Loop::get() — see https://github.com/reactphp/event-loop/releases/tag/v1.2.0
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.

7 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy