// WaitWithTimeout wait for signal return remain wait time, and is interrupted
WaitWithTimeout wait for signal return remain wait time, and is interrupted
// WaitWithTimeout wait for signal return remain wait time and is interrupted
func (cond *TimeoutCond) WaitWithTimeout(timeout time.Duration) (time.Duration, bool) {
	cond.setHasWaiters(true)
	ch := cond.signal
	cond.L.Unlock()
	defer cond.setHasWaiters(false)
	defer cond.L.Lock()
	begin := time.Now().UnixNano()
	select {
	case _, ok := <-ch:
		end := time.Now().UnixNano()
		remainTimeout := timeout - time.Duration(end-begin)
		return remainTimeout, !ok
	case <-time.After(timeout):
		return 0, false
	}
}
func ( cond * TimeoutCond ) WaitWithTimeout ( timeout time . Duration ) ( time . Duration , bool ) { cond . setHasWaiters ( true ) ch := cond . signal cond . L . Unlock ( ) defer cond . setHasWaiters ( false ) defer cond . L . Lock ( ) begin := time . Now ( ) . UnixNano ( ) select { case _ , ok := <- ch : end := time . Now ( ) . UnixNano ( ) remainTimeout := timeout - time . Duration ( end - begin ) return remainTimeout , ! ok case <- time . After ( timeout ) : return 0 , false } }
WaitWithTimeout wait for signal return remain wait time, and is interrupted
WaitWithTimeout wait for signal return remain wait time and is interrupted
//wait should unlock mutex,  if not will cause deadlock