fix: fix relay openai panic

This commit is contained in:
CaIon
2024-01-10 19:26:11 +08:00
parent d04d2a6c4d
commit 701a28d0da
2 changed files with 17 additions and 1 deletions

16
common/go-channel.go Normal file
View File

@@ -0,0 +1,16 @@
package common
func SafeSend(ch chan bool, value bool) (closed bool) {
defer func() {
// Recover from panic if one occured. A panic would mean the channel was closed.
if recover() != nil {
closed = true
}
}()
// This will panic if the channel is closed.
ch <- value
// If the code reaches here, then the channel was not closed.
return false
}