Replace clears the value on the underlying channel, and sends the new value. It's expected to be used with a size-1 channel, to only keep the most up-to-date item. This method is inherently racy when invoked concurrently from multiple goroutines.
(value any)
| 50 | // up-to-date item. This method is inherently racy when invoked concurrently |
| 51 | // from multiple goroutines. |
| 52 | func (c *Channel) Replace(value any) { |
| 53 | for { |
| 54 | select { |
| 55 | case c.C <- value: |
| 56 | return |
| 57 | case <-c.C: |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // SendContext sends value on the underlying channel, or returns an error if |
| 63 | // the context expires. |
no outgoing calls