MCPcopy Create free account
hub / github.com/ElementsProject/lightning / subscribe

Method subscribe

plugins/src/lib.rs:145–158  ·  view source on GitHub ↗

Subscribe to notifications for the given `topic`. The handler is an async function that takes a `Plugin ` and the notification as a `serde_json::Value` as inputs. Since notifications do not expect a result the handler should only report errors while processing. Any error reported while processing the notification will be logged in the cln logs. ``` use cln_plugin::{options, Builder, Error, Plug

(mut self, topic: &str, callback: C)

Source from the content-addressed store, hash-verified

143 /// .subscribe("connect", connect_handler);
144 /// ```
145 pub fn subscribe<C, F>(mut self, topic: &str, callback: C) -> Builder<S, I, O>
146 where
147 C: Send + Sync + 'static,
148 C: Fn(Plugin<S>, Request) -> F + 'static,
149 F: Future<Output = Result<(), Error>> + Send + Sync + 'static,
150 {
151 self.subscriptions.insert(
152 topic.to_string(),
153 Subscription {
154 callback: Box::new(move |p, r| Box::pin(callback(p, r))),
155 },
156 );
157 self
158 }
159
160 /// Add a subscription to a given `hookname`
161 pub fn hook<C, F>(mut self, hookname: &str, callback: C) -> Self

Callers 2

joinMethod · 0.45
mainFunction · 0.45

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected