From eb72bb97127856c5a75a4ee500164663073dd448 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 Jan 2024 17:18:29 -0800 Subject: [PATCH] fn: add SendOrQuit --- fn/send.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 fn/send.go diff --git a/fn/send.go b/fn/send.go new file mode 100644 index 000000000..4258ca536 --- /dev/null +++ b/fn/send.go @@ -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 + } +}