Skip to content

Is there a nicer way to use map and race? #484

Open
@dignifiedquire

Description

@dignifiedquire

Trying to use .map from futures::future::FutureExt and .race from async_std, the best thing I came up with is

let interrupt_chan = futures::future::FutureExt::map(receive.recv(), |_| IdleResult::Interrupt);
let idle_chan = futures::future::FutureExt::map(idle_stream.take(1).collect::<Vec<_>>(), |_| {
  IdleResult::Message
});

let idle_result = interrupt_chan.race(idle_chan).await;

but I would like to write

let interrupt_chan = receive.recv().map(|_| IdleResult::Interrupt);
let idle_chan = idle_stream.take(1).collect::<Vec<_>>().map(|_| {
  IdleResult::Message
});

let idle_result = interrupt_chan.race(idle_chan).await;

I believe this is a general issues with methods provided by futures vs async_std at the moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions