本文整理匯總了Golang中bitwrk.Logger.Print方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Print方法的具體用法?Golang Logger.Print怎麽用?Golang Logger.Print使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitwrk.Logger
的用法示例。
在下文中一共展示了Logger.Print方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: watchdog
// Closes resources upon exit of a function or when some condition no longer holds
// Arguments:
// - exitChan: Signals the watchdog to exit
// - closerChan: Signals the watchdog to add an io.Closer to the list of closers
// - f: Defines the OK condition. When false, all current closers are closed
func (t *Trade) watchdog(log bitwrk.Logger, exitChan <-chan bool, closerChan <-chan io.Closer, f func() bool) {
closers := make([]io.Closer, 0, 1)
for {
select {
case closer := <-closerChan:
closers = append(closers, closer)
case <-exitChan:
// Exit from watchdog if surrounding function has terminated
log.Print("Watchdog exiting by request")
return
default:
}
// Check if condition still holds
t.condition.L.Lock()
ok := f()
t.condition.L.Unlock()
if !ok {
log.Printf("Watchdog: closing %v channels", len(closers))
for _, c := range closers {
err := c.Close()
if err != nil {
log.Printf("Error closing channel: %v", err)
}
}
closers = closers[:0] // clear list of current closers
}
time.Sleep(250 * time.Millisecond)
}
}