Skip to content

Document use of future::timeout in combination with channels #411

Open
@yoshuawuyts

Description

@yoshuawuyts

As shared here, channels could potentially deadlock if the capacity isn't large enough:

let (s, r) = channel(1);

s.send(1).await;
s.send(2).await; // this will hang indefinitely

Instead we should probably mention that by using future::timeout this can be prevented from hanging indefinitely:

let (s, r) = channel(1);

future::timeout(s.send(1), Duration::from_secs(1).await);
future::timeout(s.send(2), Duration::from_secs(1).await);

Perhaps we could even mention in the docs that folks should probably default to something spacious such as 256 or 1024 messages in case of doubt. In general we probably shouldn't assume people have intuition about channels, and nudging them towards some safer default choices (because unlike with unbounded channels they have to choose) wouldn't be a bad idea probably (:

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions