Skip to content

Commit

Permalink
Add a subscription manager (#548)
Browse files Browse the repository at this point in the history
* WIP: Add a subscription manager.

The idea is to use the `Subscriptions` struct from Substrate, which
is used to drive subscription futures to completion, and modify
it for "general" use.

* Allow IdProvider::Id and SubscriptionId to work together

Adds trait bounds that allow conversion between the two, removing
the need for generics in SubscriptionId.

* Update SubscriptionId tests

* Rustfmt

* Use `SubscriptionId` as the key for `active_subscriptions`

* Add subscription ID providers.

Adds two subscription ID providers which can be used
by the SubscriptionManager. One provides a simple numeric
ID, while the other provides a random string.

* Add some documentation

* Clean up comment and naming

* Change the NumericIdProvider to use `u64` IDs

Instead of providing a guarantee that we can convert between
`usize` and `u64` we make the assumptions that it's unlikely
that we're running on an architecture larger than 64-bits and
we use a `u64` directly.

* Add tests for IdProvider and SubscriptionManager

Note: There's one test that doesn't pass yet which has to do
with the `cancel()` function of the SubscriptionManager.

* Restore RandomStringIdProvider as the default provider

* Retain receiver.:

* Make test executor a lazy static

* Rustfmt

* Add a comment to test

* Remove `matches!` macro

Our Windows CI runner isn't up to date and thinks this
is still a nightly feature

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
  • Loading branch information
HCastano and tomusdrw authored May 27, 2020
1 parent 0d31c50 commit 1779dbe
Show file tree
Hide file tree
Showing 4 changed files with 464 additions and 27 deletions.
3 changes: 3 additions & 0 deletions pubsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ log = "0.4"
parking_lot = "0.10.0"
jsonrpc-core = { version = "14.1", path = "../core" }
serde = "1.0"
rand = "0.7"

[dev-dependencies]
jsonrpc-tcp-server = { version = "14.1", path = "../tcp" }
futures = { version = "0.3", features = ["compat", "thread-pool"] }
lazy_static = "1.4"

[badges]
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}
1 change: 1 addition & 0 deletions pubsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate log;

mod delegates;
mod handler;
pub mod manager;
pub mod oneshot;
mod subscription;
pub mod typed;
Expand Down
Loading

0 comments on commit 1779dbe

Please sign in to comment.