Skip to content

reflect: Value.TryRecv is ambiguous #7078

@dvyukov

Description

@dvyukov
The signature and docs are:

// TryRecv attempts to receive a value from the channel v but will not block.
// It panics if v's Kind is not Chan.
// If the receive cannot finish without blocking, x is the zero Value.
// The boolean ok is true if the value x corresponds to a send
// on the channel, false if it is a zero value received because the channel is closed.
func (v Value) TryRecv() (x Value, ok bool) {

The problem is that there are actually 3 possible outcomes:
1. receive a sent value
2. the chan is closed
3. neither of above (nonblocking return)

At least we need to update docs to describe what is returned in case 3.
A bigger issue is that the signature does not allow to distinguish between all 3 cases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions