Given a channel of length N, I want to write to it only if it is not full. Else I will drop this package and process the next one.
Is this possible in GOlang
You can use select . Example:
select
package main func main() { ch := make(chan int, 2) for i := 0; i < 10; i++ { select { case ch <- i: // process this packet println(i) default: println("full") // skip the packet and continue } } }
A little after I know, but this is exactly what is implemented by the OverflowingChannel type in the helper package that I wrote. It effectively uses the selected trick above.
OverflowingChannel