Skip to content

Using inside tokio::spawn #100

@mzigan

Description

@mzigan

Hello everyone!

How to avoid mistakes when using inside tokio::spawn?

use xrpl::asynch::clients::AsyncJsonRpcClient;
use xrpl::asynch::transaction::sign_and_submit;
use xrpl::asynch::wallet::generate_faucet_wallet;
use xrpl::models::transactions::account_set::AccountSet;

#[tokio::main]
async fn main() {
    tokio::spawn(async {
        let client = AsyncJsonRpcClient::connect("https://testnet.xrpl-labs.com/".parse().unwrap());
        // Create a new wallet we can use to sign the transaction
        let wallet = generate_faucet_wallet(&client, None, None, None, None)
            .await
            .unwrap();
        // Define the transaction we want to sign
        let mut account_set = AccountSet::new(
            wallet.classic_address.clone().into(),
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            Some("6578616d706c652e636f6d".into()), // example.com
            None,
            None,
            None,
            None,
            None,
            None,
        );
        println!("AccountSet transaction before signing: {:?}", account_set);
        // Sign and submit the transaction
        sign_and_submit(&mut account_set, &client, &wallet, true, true)
            .await
            .unwrap();
        println!("AccountSet transaction after signing: {:?}", account_set);
    });
}
error: implementation of `Send` is not general enough
  --> src/main.rs:8:5
   |
8  | /     tokio::spawn(async {
9  | |         let client = AsyncJsonRpcClient::connect("https://testnet.xrpl-labs.com/".parse().unwrap());
10 | |         // Create a new wallet we can use to sign the transaction
11 | |         let wallet = generate_faucet_wallet(&client, None, None, None, None)
...  |
40 | |         println!("AccountSet transaction after signing: {:?}", account_set);
41 | |     });
   | |______^ implementation of `Send` is not general enough
   |
   = note: `Send` would have to be implemented for the type `&AsyncJsonRpcClient`
   = note: ...but `Send` is actually implemented for the type `&'0 AsyncJsonRpcClient`, for some specific lifetime `'0`

error: implementation of `Send` is not general enough
  --> src/main.rs:8:5
   |
8  | /     tokio::spawn(async {
9  | |         let client = AsyncJsonRpcClient::connect("https://testnet.xrpl-labs.com/".parse().unwrap());
10 | |         // Create a new wallet we can use to sign the transaction
11 | |         let wallet = generate_faucet_wallet(&client, None, None, None, None)
...  |
40 | |         println!("AccountSet transaction after signing: {:?}", account_set);
41 | |     });
   | |______^ implementation of `Send` is not general enough
   |
   = note: `Send` would have to be implemented for the type `&std::string::String`
   = note: ...but `Send` is actually implemented for the type `&'0 std::string::String`, for some specific lifetime `'0`

error: implementation of `Send` is not general enough
  --> src/main.rs:8:5
   |
8  | /     tokio::spawn(async {
9  | |         let client = AsyncJsonRpcClient::connect("https://testnet.xrpl-labs.com/".parse().unwrap());
10 | |         // Create a new wallet we can use to sign the transaction
11 | |         let wallet = generate_faucet_wallet(&client, None, None, None, None)
...  |
40 | |         println!("AccountSet transaction after signing: {:?}", account_set);
41 | |     });
   | |______^ implementation of `Send` is not general enough
   |
   = note: `Send` would have to be implemented for the type `&str`
   = note: ...but `Send` is actually implemented for the type `&'0 str`, for some specific lifetime `'0`

error: lifetime bound not satisfied
  --> src/main.rs:8:5
   |
8  | /     tokio::spawn(async {
9  | |         let client = AsyncJsonRpcClient::connect("https://testnet.xrpl-labs.com/".parse().unwrap());
10 | |         // Create a new wallet we can use to sign the transaction
11 | |         let wallet = generate_faucet_wallet(&client, None, None, None, None)
...  |
40 | |         println!("AccountSet transaction after signing: {:?}", account_set);
41 | |     });
   | |______^
   |
   = note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status

🆕 New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions