Standard library / reflect
reflect.Value.TrySend()
Attempts a send without blocking and reports whether it succeeded. Sending on a closed channel still panics. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) TrySend(x Value) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | Value | Value assignable to the channel element type. |
Return Value
bool
Attempts a send without blocking and reports whether it succeeded.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { ch := make(chan int, 1) v := reflect.ValueOf(ch) fmt.Println(v.TrySend(reflect.ValueOf(1)), v.TrySend(reflect.ValueOf(2)))}