Skip to content

Add Race::race_with_index #210

@tyilo

Description

@tyilo

I think the following race_with_index function would be very useful:

pub trait Race {
    type Output;
    type Future: Future<Output = Self::Output>;

    fn race(self) -> Self::Future;

    // New method:
    fn race_with_index(self) -> impl Future<Output = (usize, Self::Output)>;
}

Usage:

let (i, result) = (fut_1, fut_2).race().await;
println!("Future {i} won the race with result {result}");

A similar function should probably also be add to RaceOk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions