-
Notifications
You must be signed in to change notification settings - Fork 8
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
PubSub and Broadcast #45
Conversation
A bit busy for now, so I'll continue working on this later the week |
This approach makes a lot of sense to me. It should be relatively simple to then create custom implementations of PubSub. I like the idea of including an example in the documentation. I also agree that making a separate package for these implementations makes sense. Nice work! |
I made some changes to simply things a bit. I changed
Basically, it applied on any upstream / subscription values to create downstream(s) and distribute messages into all downstream(s), where:
I think I should stop here to not add any more bloat and increase the surface area where bug can occur in the library. |
The constraint on what type can an |
Motivation
PubSub
By exporting the protocol,
PubSub
, it allow different implementation ofAsyncPubSub
notably implementation backed by popular event-publishing systems (i.e. Redis) with similar API which allow user of this library to prototype with the in memoryAsyncPubSub
and easily migrate to a distributedPubSub
implementation without very little changes.Broadcast
Additionally, common client libraries for popular event-publishing systems usually only provide a function that to subscribe to a specific publisher, but no option of unsubscribing without closing the publisher entirely and sometimes only allow 1 subscriber for each publisher (usually because subscription is its own new network connection).
1st proposal
In this case, the protocol, `Broadcast`, is exported which allow a `PubSub` to broadcast the subscription values to multiple different downstream where each downstream share the same upstream and can be unsubscribed / disposed (to prevent leaks) without closing the upstream and publisher. Any `PubSub` can be optionally conform to this protocol which will need to implementation a different sets of functions, but will be provided with the required functions to conforms to `PubSub`.An example of this is
AsyncPubSub
itself, which store 1 source upstream for each topic but for each subscription, it will create a new downstream and broadcast the messages from the upstream to all of the downstream. This way, there can multiple subscriber for each upstream (topic) and each subscriber downstream can be disposed without closing the source stream (which will close all subscriber for that topic).2nd proposal
In this case, the observer actor,
Broadcast
, is provided which can broadcast any subscription values to multiple different downstream where each downstream share the same upstream and can be unsubscribed / disposed (to prevent leaks) without closing the upstream and publisher.For instance
Optional
Both of these are optional, you can still implement a Pub/Sub without utilizing both of them. As long as that Pub/Sub can return an
AsyncSequence
, it will work with Pioneer.Tasks
PubSub
, that define a method specification forAsyncPubSub
Broadcast
that define a specification forPubSub
that require broadcasting capabilities with actorBroadcast
Broadcast
to be a streaming middleware actor that handle distribution of downstream(s)EventStream
part of documentationReference
part of documentation to includePubSub
andBroadcast
PubSub
section in eitherEventStream
orFeatures
to give clear explanation for making customPubSub
implementation