fn: add SendOrQuit

This commit is contained in:
Olaoluwa Osuntokun 2024-01-02 17:18:29 -08:00
parent a2694009cd
commit eb72bb9712
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

13
fn/send.go Normal file
View File

@ -0,0 +1,13 @@
package fn
// SendOrQuit attempts to and a message through channel c. If this succeeds,
// then bool is returned. Otherwise if a quit signal is received first, then
// false is returned.
func SendOrQuit[T any, Q any](c chan<- T, msg T, quit chan Q) bool {
select {
case c <- msg:
return true
case <-quit:
return false
}
}