Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: make event types thread safe #341

Merged
merged 1 commit into from
Jul 13, 2021
Merged

fix: make event types thread safe #341

merged 1 commit into from
Jul 13, 2021

Conversation

gakonst
Copy link
Owner

@gakonst gakonst commented Jul 13, 2021

Fixes the repro shown here by making the Event Types Send + Sync.

Previously, this would not work:

#[tokio::main]
async fn main() -> AnyError {
    tokio::task::spawn(async move {
        let ws = Ws::connect("wss://mainnet.infura.io/ws/v3/[API-KEY]").await.unwrap();
        let provider = Arc::new(Provider::new(ws).interval(Duration::from_millis(500)));
        let address = Address::from_str("0xdac17f958d2ee523a2206206994597c13d831ec7").unwrap();
        let contract = token_contract::TokenContract::new(address, provider);

        let filter = contract.transfer_filter();
        let mut stream = filter.stream().await.unwrap();

        while let Some(block) = stream.next().await {
            dbg!(block);
        }
    }).await;

    Ok(())
}

@gakonst gakonst merged commit 04bbd1b into master Jul 13, 2021
@gakonst gakonst deleted the event-threadsafe branch July 13, 2021 11:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant