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

Add a SharedClient and SharedServer #72

Closed
tomaka opened this issue Nov 21, 2019 · 2 comments · Fixed by #80
Closed

Add a SharedClient and SharedServer #72

tomaka opened this issue Nov 21, 2019 · 2 comments · Fixed by #80
Labels
enhancement New feature or request

Comments

@tomaka
Copy link
Contributor

tomaka commented Nov 21, 2019

After some discussion with @jimpo, let's make the API more convenient to use.

As a first step, let's add a SharedClient and a SharedServer. See the sketches below.
As a second step, let's rename things around: RawClient/RawServer should become ClientTransport/ServerTransport, Client/Server should become RawClient/RawServer, and SharedClient/SharedServer should become Client/Server.

Sketches for the new API layers:

impl SharedClient<...> {
    pub async fn request<Ret>(&self, method: ..., params: ...) -> Ret;
    pub async fn subscribe(&self, method: ..., params: ...) -> Subscription;
}

impl Subscription {
    pub async fn next(&mut self) -> ...;
}

impl Drop for Subscription {
    ...  // unsubscribes
}
impl SharedServer<...> {
    /// Registers a request that the server must handle. Returns an error if already registered.
    pub fn register_request<Params, Ret>(&self, method: ...) -> RequestHandler<Params, Ret>;
    pub fn register_subscription<Notif>(&self, subscribe_method: ..., unsubscribe_method: ...) -> Subscription<Notif>;
}

impl<Params, Ret> RequestHandler<Params, Ret> {
    /// User must call this repeatedly and answer the requests.
    pub async fn next(&mut self) -> ...;
}

impl<Notif> Subscription<Notif> {
    pub async fn send_all(&self, to_send: Notif) { ... }
}
@tomaka tomaka added the enhancement New feature or request label Nov 21, 2019
@tomaka tomaka added this to the First release on crates.io milestone Nov 21, 2019
@tomaka
Copy link
Contributor Author

tomaka commented Nov 21, 2019

Since we can't implement SharedClient/SharedServer in a no_std environment, we theoretically shouldn't put them in jsonrpsee-core but in a different crate.
Note that local.rs would be concerned as well.

@tomaka
Copy link
Contributor Author

tomaka commented Nov 21, 2019

A nice property of SharedClient/SharedServer is that they don't need any template parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant