ably-labs / ably-chat-kotlin

Ably Chat SDK for Android
Apache License 2.0
1 stars 1 forks source link

[RTE1] Implement non-blocking emitter #41

Open sacOO7 opened 2 weeks ago

sacOO7 commented 2 weeks ago

┆Issue is synchronized with this Jira Task by Unito

sacOO7 commented 2 weeks ago

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

  1. Flow based eventemitter - https://github.com/ably-labs/ably-chat-kotlin/pull/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 -> https://github.com/ably-labs/ably-chat-kotlin/pull/35#discussion_r1814924152
    • Likely to cause change in public API interface, also hot flows can slow down other subscribers.
  2. 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 -> https://github.com/ably-labs/ably-chat-kotlin/pull/40