Skip to content

Emit events on blocking operations #176

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

Closed
EligiusSantori opened this issue Apr 30, 2025 · 3 comments
Closed

Emit events on blocking operations #176

EligiusSantori opened this issue Apr 30, 2025 · 3 comments
Labels

Comments

@EligiusSantori
Copy link

EligiusSantori commented Apr 30, 2025

Please propagate DuplexStreamInterface::on('data') as normal event not just a promise.
Promises are only fit when you need to do a single call.
When you need a BLPOP/XREAD/XREADGROUP-based endless reading loop, event is a must have.
I think you can use command name as an event name so user will be able to choose what to handle.

@clue clue added the question label May 1, 2025
@clue
Copy link
Owner

clue commented May 1, 2025

@EligiusSantori Welcome to this library! If I understand your problem correctly, then there should be no need for any additional events. Each Redis command follows request-response semantics as described in https://github.com/clue/reactphp-redis#commands.

This means that either of your commands has to be used in a loop (or using async callbacks) and each invocation returns exactly one piece of data (or a null marker if empty), see also #95 and #102 for some pointers. I've built a number of queuing systems and event brokers for commercial projects using this approach and don't see anything that's missing here at the moment. If this sounds like you, you can always shoot me an email to discuss possible support options.

I hope this helps! 👍 If so, consider supporting this project, for example by becoming a sponsor ❤️

@clue clue closed this as completed May 1, 2025
@EligiusSantori
Copy link
Author

EligiusSantori commented May 2, 2025

Do you absolutely sure that interpreter optimizes recursion over promises there? There is 3 ways to implement it and none of them is robust enough.

  1. Recursive promises as you said. Requires faith that PHP won't create a frame in call stack every iteration in complex code.
  2. Async/await loop in endless futureTick() handler. But futureTick() is not intended for such tasks so there is no garantee that it won't be cleared/overwritten by some reason / in some ReactPHP version.
  3. Lame way through addPeriodicTimer().

Anyway, emitting data event is not enough there because errors should be handled too. I decided to make my own implementation of Redis client dedicated for streams which is based on StreamingClient class.

@clue
Copy link
Owner

clue commented May 2, 2025

Don't get me wrong, we can definitely theorize hypothetical problems all day. You seem to imply there's some kind of potential problem with the existing approach or some future potential development, perhaps you can help me understand what problem you're seeing exactly?

You can already use await($redis->callAsync(…)) today, plus $redis->call(…) in the future (#166). In either case, I don't see any of the problems you're describing.

If you want to learn more about the roadmap for future ReactPHP v3, you may want to check out https://github.com/orgs/reactphp/discussions/481.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants