Giter VIP home page Giter VIP logo

Comments (7)

yukibtc avatar yukibtc commented on May 18, 2024

I tried to implement Drop for RelayPool but this cause many issues in a multi-threads env (like https://github.com/coinstr/coinstr) where the Client is cloned and dropped many times.

For now the only way to completely shutdown the client is to exit from the app (the threads will drop) or by calling the shutdown method.

from nostr.

yukibtc avatar yukibtc commented on May 18, 2024

An alternative to shutdown is the stop method: it allow to re-start a previously constructed Client (anyway it must be called manually) by calling the start method.

from nostr.

benthecarman avatar benthecarman commented on May 18, 2024

Just something to kill the connections on drop would be nice, have run into the problem multiple times on accident

from nostr.

yukibtc avatar yukibtc commented on May 18, 2024

Maybe you can wrap the Client:

pub struct CustomClient {
    inner: Client
}

impl Drop for CustomClient {
    fn drop(&mut self) {
        let client = self.clone();
        async_utility::thread::spawn(async move {
            client.shutdown().await.unwrap();
        });
    }
}

I can't implement the Drop because if a user do this

let client = self.clone();
thread::spawn(async move {
    // use client and then drop
});

the client shutdown everywhere.

from nostr.

yukibtc avatar yukibtc commented on May 18, 2024

Otherwise, I'll try to add a new filed in Options, like shutdown_on_drop: bool (by default will be disabled).
If you'll initialize the Client with that option enabled, the Client will shutdown on drop.
What do you think?

from nostr.

benthecarman avatar benthecarman commented on May 18, 2024

That sounds good

from nostr.

yukibtc avatar yukibtc commented on May 18, 2024

Done

So, init the Client in this way:

// ...
let opts = Options::new().shutdown_on_drop(true);
let client = Client::with_opts(&keys, opts);
// ...

from nostr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.