ai_scheduler/internal/pkg/func.go

24 lines
738 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package pkg
import (
"ai_scheduler/internal/entitys"
"encoding/json"
)
func JsonStringIgonErr(data interface{}) string {
dataByte, _ := json.Marshal(data)
return string(dataByte)
}
// IsChannelClosed 检查给定的 channel 是否已经关闭
// 参数 ch: 要检查的 channel类型为 chan entitys.ResponseData
// 返回值: bool 类型true 表示 channel 已关闭false 表示未关闭
func IsChannelClosed(ch chan entitys.ResponseData) bool {
select {
case _, ok := <-ch: // 尝试从 channel 中读取数据
return !ok // 如果 ok=false说明 channel 已关闭
default: // 如果 channel 暂时无数据可读(但不一定关闭)
return false // channel 未关闭(但可能有数据未读取)
}
}