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

rpc module: add call_and_subscribe #588

Merged
merged 8 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions types/src/v2/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct Request<'a> {
}

impl<'a> Request<'a> {
/// Create a new `Request`.
/// Create a new [`Request`].
pub fn new(method: Cow<'a, str>, params: Option<&'a RawValue>, id: Id<'a>) -> Self {
Self { jsonrpc: TwoPointZero, id, method, params }
}
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct Notification<'a, T> {
}

impl<'a, T> Notification<'a, T> {
/// Create a new `Notification`.
/// Create a new [`Notification`].
pub fn new(method: Cow<'a, str>, params: T) -> Self {
Self { jsonrpc: TwoPointZero, method, params }
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/v2/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Response<'a, T> {
}

impl<'a, T> Response<'a, T> {
/// Create a new `Response`.
/// Create a new [`Response`].
pub fn new(result: T, id: Id<'a>) -> Response<'a, T> {
Response { jsonrpc: TwoPointZero, result, id }
}
Expand Down
16 changes: 12 additions & 4 deletions utils/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,18 @@ impl Methods {
rx.next().await
}

/// Perform a method call and receive further subscriptions.
/// Perform a "in memory JSON-RPC method call" and receive further subscriptions.
/// This is useful if you want to support both `method calls` and `subscriptions`
/// in the same API.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
///
/// Returns a response to actual method call and a stream to process
/// futher subscriptions if a subcription was registered on the call.
/// There are better variants than this method if you only want
/// method calls or subscriptions.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
///
/// See [`Methods::test_subscription`] and [`Methods::call_with`] for
/// for further documentation.
///
/// Returns a response to the actual method call and a stream to process
/// further notifications if a subscription was registered by the call.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
///
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
/// ```
/// #[tokio::main]
Expand All @@ -386,7 +394,7 @@ impl Methods {
///
/// let mut module = RpcModule::new(());
/// module.register_subscription("hi", "hi", "goodbye", |_, mut sink, _| {
/// sink.send(&"one answer").unwrap();
/// sink.send(&"one answer").unwrap();
/// Ok(())
/// }).unwrap();
/// let (resp, mut stream) = module.call_and_subscribe("hi", EmptyParams::new()).await.unwrap();
Expand Down