Skip to content

proposal: a new syntax for sending values to channels #18511

@yaxinlx

Description

@yaxinlx

Now, sending values to closed channels will panic, and sending values to channels is viewed as non-blocking operation. The two facts combined limits the possibilities of using the select mechanics.
So I proposal a special syntax for sending values to channels:

aChannel <-| value

When using this syntax to send values to closed channels, it will not panic but block the current goroutine. In other words, sending values to closed channels with the new syntax will be viewed as a blocking operation. This will create more possibilities to use the select mechanics.

Maybe adding another one would be better

aChannel <-? value

When using this syntax to send values to closed channels, it will neither panic nor block the current goroutine. In other words, sending values to closed channels with this new syntax is a no-op.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions