Skip to content

Commit

Permalink
Fix: Remove Sync requirements on Futures returned in the Rust plugin …
Browse files Browse the repository at this point in the history
…library.

See: bitcoindevkit/bdk#1047 (comment)

In general, futures produced by most libraries in the ecosystem of Rust, and bounds placed
on users of famous runtimes like tokio and its spawn method all lack Sync requirements.

Because of this, anyone who creates a callback using any sort of library that returns a
non-Sync future (which most libraries fit this description) inside of it will get some
cryptic error messages (async error messages still leave a lot to be desired).

Removing these Sync requirements will make the library more useful.
  • Loading branch information
junderw committed Aug 3, 2023
1 parent 568f277 commit d163230
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
impl<S, I, O> Builder<S, I, O>
where
O: Send + AsyncWrite + Unpin + 'static,
S: Clone + Sync + Send + Clone + 'static,
S: Clone + Sync + Send + 'static,
I: AsyncRead + Send + Unpin + 'static,
{
pub fn new(input: I, output: O) -> Self {
Expand Down Expand Up @@ -146,7 +146,7 @@ where
where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Request) -> F + 'static,
F: Future<Output = Result<(), Error>> + Send + Sync + 'static,
F: Future<Output = Result<(), Error>> + Send + 'static,
{
self.subscriptions.insert(
topic.to_string(),
Expand All @@ -162,7 +162,7 @@ where
where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Request) -> F + 'static,
F: Future<Output = Response> + Send + Sync + 'static,
F: Future<Output = Response> + Send + 'static,
{
self.hooks.insert(
hookname.to_string(),
Expand All @@ -179,7 +179,7 @@ where
where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Request) -> F + 'static,
F: Future<Output = Response> + Send + Sync + 'static,
F: Future<Output = Response> + Send + 'static,
{
self.rpcmethods.insert(
name.to_string(),
Expand Down Expand Up @@ -504,7 +504,7 @@ where

impl<S> PluginDriver<S>
where
S: Send + Clone + Sync,
S: Send + Clone,
{
/// Run the plugin until we get a shutdown command.
async fn run<I, O>(
Expand Down

0 comments on commit d163230

Please sign in to comment.