-
Notifications
You must be signed in to change notification settings - Fork 267
Add a subscription manager #548
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
Changes from 1 commit
7ef90a3
9883720
a41638e
05b1a92
0149fd4
f0fabd9
c89511d
cd31378
3cf3113
7e435a0
1e5846f
1334760
476edee
c3dafbc
52caa9a
2c27a2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
SubscriptionId as the key for active_subscriptions
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||
| //! Provides an executor for subscription Futures. | ||||||
|
|
||||||
| use std::collections::HashMap; | ||||||
| use std::hash::Hash; | ||||||
| use std::sync::Arc; | ||||||
|
|
||||||
| use crate::core::futures::sync::oneshot; | ||||||
|
|
@@ -19,7 +18,7 @@ pub type TaskExecutor = Arc<dyn future::Executor<Box<dyn Future<Item = (), Error | |||||
| /// Trait used to provide unique subscription ids. | ||||||
| pub trait IdProvider { | ||||||
| /// A unique ID used to identify a subscription. | ||||||
| type Id: Copy + Clone + Default + Eq + Hash + Into<SubscriptionId> + From<SubscriptionId>; | ||||||
| type Id: Copy + Clone + Default + Into<SubscriptionId>; | ||||||
|
|
||||||
| /// Returns next id for the subscription. | ||||||
| fn next_id(&self) -> Self::Id; | ||||||
|
|
@@ -32,7 +31,7 @@ pub trait IdProvider { | |||||
| #[derive(Clone)] | ||||||
| pub struct SubscriptionManager<I: Default + IdProvider> { | ||||||
|
||||||
| pub struct SubscriptionManager<I: Default + IdProvider> { | |
| pub struct SubscriptionManager<I: IdProvider = RandomizedStringProvider> { |
We should implement two IdProviders:
NumericIdProviderRandomizedStringProvider
The first one would simply use AtomicU64 and would return increasing numeric values, the second one - which should also be a default to use if SubscriptionManager does not include generic parameter - should return a randomized strings (guids).
The reason for using randomized strings is to make sure that subscription ids are not easy to guess, so that multiple clients can't cancel each-others subscriptions easily. The first one will be mostly usable for tests or cases where the aforementioned issue is not a problem.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO It's fine, in most workloads spawning subscription is not going to be a bottleneck so we can safely do a virtual call here.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| executor: TaskExecutor, // Make generic? | |
| executor: TaskExecutor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should expand on this module description a bit. The subscription manager is opinionated way to handle processing subscriptions that are based on
Streamcoming from the user codebase.The manager takes care of:
Streamof events (coming from user code) and transforming it into a subscription notifications to the client.