How do I re-execute a task (with a different parameter) in a FuturesUnordered on error and keep count?

So I've got the following draft:

//Start latency timer, for rate limitting of the jsonrpc api
    std::thread::spawn(|| timers::count_down_rpc());

    //Spawn tasks that check if the addresses are contracts
    let mut tasks = FuturesUnordered::new();
    let mut contracts: HashMap<String, bool> = HashMap::new();

    for entry in addr_vec {
        let url = setting.jsonrpc.url_1.clone();
        let address = entry.address.clone();
        let latency = setting.jsonrpc.latency_1;

        let container = jsonrpc::IsContractResponse {
            address: address,
            is_contract: false,
            count: 0,

        let sleep_time = std::time::Duration::from_millis(timers::get_sleep_time_rpc() as u64);

        tasks.push(tokio::spawn(async move {
            jsonrpc::is_contract(container, url).await

    while let Some(finished_task) = {
        if finished_task.is_err() {
                "JoinError while scanning for contract: \n{}",

        match finished_task.unwrap() {
            Err(e) => {
                //!!!! Get container.count, push latency to custom timer and re-execute with different url from pool
            Ok(v) => {
                if v.is_contract {
                    contracts.insert(v.address, false);

I didn't think in advance I just went along step by step so I didn't foresee that on error I wouldn't have access to the container.count and container.address values. I was thinking of creating a custom Error that appends the isContractResponse struct to the error. But this would be messy as hell, but it might be my best bet. Because I need to keep count of how many times I've tried to check the specific address.

So I was wondering if any of you pros knew of a better way to do what I'm trying to do.

The full code is at any comment on the code is much appreciated. This is my first go at rust (pun intended)

You will need to change the is_contract function to return the object on error as well.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.