I'm using the below type in my code:
pub struct Account<T> {
client: Arc<dyn ProgramClient<T>>,
payer: Arc<dyn Signer>,
nonce_authority: Option<Arc<dyn Signer>>,
}
This is from a foreign crate so I don't have access to any of the types. I use this type in async functions on which I call await
, so I was under the assumption (but I might be totally wrong on this) that this type was Send
and Sync
.
However, when trying to do the below:
tokio::spawn(async move {
Account::new(
get_program_rpc(Arc::clone(&client)),
Arc::new(Keypair::from_base58_string(&config.buyer_private_key))
)
.get_account_info(&Pubkey::default())
.await;
});
I get the error:
future cannot be sent between threads safely
the trait `std::marker::Sync` is not implemented for `(dyn spl_token_client::client::ProgramClient<spl_token_client::client::ProgramRpcClientSendTransaction> + 'static)`
instant_swap.rs(47, 14): future is not `Send` as this value is used across an await
spawn.rs(166, 21): required by a bound in `tokio::spawn`
future cannot be sent between threads safely
the trait `std::marker::Send` is not implemented for `(dyn spl_token_client::client::ProgramClient<spl_token_client::client::ProgramRpcClientSendTransaction> + 'static)`
instant_swap.rs(47, 14): future is not `Send` as this value is used across an await
spawn.rs(166, 21): required by a bound in `tokio::spawn`
future cannot be sent between threads safely
the trait `std::marker::Sync` is not implemented for `(dyn solana_sdk::signature::Signer + 'static)`
instant_swap.rs(47, 14): future is not `Send` as this value is used across an await
spawn.rs(166, 21): required by a bound in `tokio::spawn`
future cannot be sent between threads safely
the trait `std::marker::Send` is not implemented for `(dyn solana_sdk::signature::Signer + 'static)`
instant_swap.rs(47, 14): future is not `Send` as this value is used across an await
spawn.rs(166, 21): required by a bound in `tokio::spawn`
Just for context, get_program_rpc
returns a Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>>
.
So clearly I'm doing something wrong, also the code
Account::new(
get_program_rpc(Arc::clone(&client)),
Arc::new(Keypair::from_base58_string(&config.buyer_private_key))
)
.get_account_info(&Pubkey::default())
.await;
works fine if I am not using it in the Tokio runtime but a normal async Rust function...
If anyone can help me understand why I'm getting this error (is it just because the type is actually !Send + !Sync
?), why it's ok in normal Rust async code and is there anything I can do to make it work?
Thanks!