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 RpcModule::remove #1416

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions core/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ impl Methods {
}
}

// Removes the method callback for a given name, if it exists.
fn remove(&mut self, name: &'static str) -> Option<MethodCallback> {
self.mut_callbacks().remove(name)
}
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

/// Helper for obtaining a mut ref to the callbacks HashMap.
fn mut_callbacks(&mut self) -> &mut FxHashMap<&'static str, MethodCallback> {
Arc::make_mut(&mut self.callbacks)
Expand Down Expand Up @@ -552,6 +557,13 @@ impl<Context: Send + Sync + 'static> RpcModule<Context> {
)
}

/// Removes method if it exists.
///
/// It is caller responsibility to remove both `subscribe` and `unsubscribe` methods for subscriptions.
pub fn remove_method(&mut self, method_name: &'static str) -> Option<MethodCallback> {
jsdw marked this conversation as resolved.
Show resolved Hide resolved
self.methods.remove(method_name)
}

/// Register a new asynchronous RPC method, which computes the response with the given callback.
///
/// ## Examples
Expand Down
Loading