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

[RTE1] Implement non-blocking emitter #41

Open
sacOO7 opened this issue Nov 4, 2024 · 1 comment
Open

[RTE1] Implement non-blocking emitter #41

sacOO7 opened this issue Nov 4, 2024 · 1 comment
Assignees

Comments

@sacOO7
Copy link

sacOO7 commented Nov 4, 2024

  • Implement thread-safe, non-blocking emitter in kotlin as per spec RTE1
  • Ideally, should expose methods that can work for both kotlin/java.
  • Should be able to process events in provided coroutinescope.
  • Ideally, events should be processed async in kotlin ( under coroutinescope ), since communication between coroutines mostly requires parent coroutine scope. i.e. users can choose to emit event via flow, channel etc while processing messages, room state changes ... This is not possible if subscribers are blocking or not running under coroutinescope.
  • Implement proper tests for the same.
  • Current event-emitter implementation in java is thread-safe, but blocks the emitter thread till all subscribers process the event
    https://github.com/ably/ably-java/blob/main/lib/src/main/java/io/ably/lib/util/EventEmitter.java

┆Issue is synchronized with this Jira Task by Unito

@sacOO7 sacOO7 self-assigned this Nov 4, 2024
@sacOO7
Copy link
Author

sacOO7 commented Nov 4, 2024

Currently, we have implemented event emitter with two different ways ->

  1. Flow based eventemitter - [ECO-5013][CHA-RL4] Flow based Event Emitter #35
  • Somehow, this doesn't fit our use-case well, since flow doesn't allow proper cancellation of collectors/subscribers.
  • We need to use hot flows, those don't close until we explicitly specify it in the code.
  • Since, this is a pull-based approach ( hot flows ), rather than emitter push, more likelyhood of causing memory leaks, without proper garbage collection
  • Tests for those doesn't work as expected, we need to add workarounds to make emitter work.
  • More information -> [ECO-5013][CHA-RL4] Flow based Event Emitter #35 (comment)
  • Likely to cause change in public API interface, also hot flows can slow down other subscribers.
  1. Emit based eventemitter
  • This solution fits our requirement, each subscriber process events independently when notified by emitter.
  • All events are processed based on emit and doesn't need to keep observing for incoming events, i.e. garbage collector will automatically clean resources when no jobs running.
  • We have proper tests for the same and works as expected, see async emitter tests
  • We have extended this emitter with GenericEmitter that works for both java/kotlin -> Replace blocking emitter with non-blocking emitter #40

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

No branches or pull requests

1 participant