event-loop icon indicating copy to clipboard operation
event-loop copied to clipboard

Add watchdog timer example

Open danepowell opened this issue 3 years ago • 4 comments

Fix #255

If you want to see this pattern in action, I have a work in progress here:

  • https://github.com/acquia/cli/pull/1101
  • https://github.com/danepowell/cli/blob/CLI-827/src/Helpers/LoopHelper.php#L10

danepowell avatar Jul 21 '22 22:07 danepowell

Hey @danepowell, I think this is a nice addition to the documentation 👍

This is also a very specific example, which is fine because it matches your use case, but it also makes this code block quite large. Would it make sense to simplify it to show the most relevant parts in this example?

Additionally the same documentation for the timer methods also exists as doc blocks inside src/LoopInterface.php, can you add them there too?

SimonFrings avatar Jul 22 '22 08:07 SimonFrings

Updated the title a bit :+1:

WyriHaximus avatar Jul 22 '22 10:07 WyriHaximus

@SimonFrings yes it's a large example, but I think in this case it makes sense in this case as it shows off a specific pattern that requires referencing an array. Maybe the iterating and resetting of the timers array could be done in a function, but that would defeat part of the example. So yes I think this bigger example is worth it as it shows off a key way of working in ReactPHP, and non-blocking programming in general.

WyriHaximus avatar Jul 23 '22 22:07 WyriHaximus

Thanks for the feedback, I refactored the example to shave off a few lines and copied it to the LoopInterface docblock.

danepowell avatar Jul 25 '22 14:07 danepowell

@danepowell Thank you for looking into this! I think having this example is definitely valuable, so it's much appreciated.

That being said, I'm not currently convinced that this particular example should be included in the project documentation. Considering the existing documentation structure, this example would become quite prominent, and I'd rather use this space to educate users about more efficient, event-driven APIs and how they're usually superior to polling logic. Additionally, this example assumes a someExternalService() function that isn't part of this project and requires it to be non-blocking. Since this is implicit, providing this example may tempt users to apply this idea to blocking functions.

Considering we're moving toward simpler, fiber-based APIs in ReactPHP v3 (see https://github.com/orgs/reactphp/discussions/481), it might also make sense to take a look at the new delay() function here.

Please share your thoughts on this. I'm open to discussion, so thank you for sparking this conversation!

clue avatar May 05 '23 08:05 clue

I'm closing this for now as it hasn't received any input in a while and I believe this has been answered. If you feel this is still relevant, please come back with more details and we can always reopen this :+1:

Thank you for your effort nonetheless, keep it up! :+1:

clue avatar Jun 25 '23 09:06 clue