// Calls a function every tick until conditionFn returns true or timeout occurs.
541173
func (t *Tab) WaitFor(rate, timeout time.Duration, conditionFn ConditionalFunc) error {
	rateTicker := time.NewTicker(rate)
	timeoutTimer := time.NewTimer(timeout)

	defer func() {
		timeoutTimer.Stop()
		rateTicker.Stop()
	}()

	for {
		select {
		case <-timeoutTimer.C:
			return &TimeoutErr{Message: "waiting for conditional func to return true"}
		case <-rateTicker.C:
			ret := conditionFn(t)
			if ret == true {
				return nil
			}
		}
	}
}
1265553
func (r *RateLimiter) Wait() {
	for {
		ok, remaining := r.Try()
		if ok {
			break
		}
		time.Sleep(remaining)
	}
}
1222110
func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
	JitterUntil(f, period, 0.0, true, stopCh)
}
731149
func AfterFunc(d time.Duration, f func()) Timer {
	return provider.AfterFunc(d, f)
}
632495
func eventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}

	cbinfo := &EventTimeoutCallbackInfo{
		callback: callback,
		opaque:   opaque,
		free:     free,
	}

	return C.int(eventLoopImpl.AddTimeoutFunc(int(freq), cbinfo))
}
1373170
func (m *mockTicker) wait(ready chan<- struct{}) {
	for i := time.Duration(1); true; i++ {
		delta := m.start.Add(m.interval * i).Sub(m.clock.Now())
		afterChan := m.clock.After(delta)

		if i == time.Duration(1) {
			ready <- struct{}{}
		}

		select {
		case <-m.stop:
			return
		case <-afterChan:
			select {
			case m.c <- m.clock.Now():
			case <-m.stop:
				return
			}
		}
	}
}
1301642
func wait(epfd, eventfd int, timeout time.Duration) (bool, error) {
	events := make([]unix.EpollEvent, numFdEvents+1)
	timeoutMS := int(timeout / time.Millisecond)
	n, err := unix.EpollWait(epfd, events, timeoutMS)
	if n == -1 {
		if err == unix.EINTR {
			// Interrupt, ignore the error
			return false, nil
		}
		return false, err
	}
	if n == 0 {
		// Timeout
		return false, nil
	}
	if n > numFdEvents {
		return false, fmt.Errorf("epoll_wait returned more events than we know what to do with")
	}
	for _, event := range events[:n] {
		if event.Fd == int32(eventfd) {
			if event.Events&unix.EPOLLHUP != 0 || event.Events&unix.EPOLLERR != 0 || event.Events&unix.EPOLLIN != 0 {
				// EPOLLHUP: should not happen, but if it does, treat it as a wakeup.

				// EPOLLERR: If an error is waiting on the file descriptor, we should pretend
				// something is ready to read, and let unix.Read pick up the error.

				// EPOLLIN: There is data to read.
				return true, nil
			}
		}
	}
	// An event occurred that we don't care about.
	return false, nil
}
890045
func (i Int16) If(fn func(int16)) {
	if i.Present() {
		fn(*i.value)
	}
}
41690
func Timeout(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "timeout", Listener: listener}
}
431034
func Do(timeout time.Duration, operation DoCondition) error {
	if timeout <= 0 {
		panic("timeout must be larger than zero")
	}

	interval := time.Duration(math.Ceil(float64(timeout) / 15.0))
	if interval > maxInterval {
		interval = maxInterval
	}

	timeout = applyCIMultiplier(timeout)

	var err error
	if err = operation(); err == nil {
		fmt.Println("+")
		return nil
	}
	fmt.Print("*")

	stopTimer := time.NewTimer(timeout)
	defer stopTimer.Stop()
	retryTick := time.NewTicker(interval)
	defer retryTick.Stop()

	for {
		select {
		case <-stopTimer.C:
			fmt.Println("-")
			return fmt.Errorf("try operation failed: %s", err)
		case <-retryTick.C:
			fmt.Print("*")
			if err = operation(); err == nil {
				fmt.Println("+")
				return err
			}
		}
	}
}
1183456
func (f Float32) If(fn func(float32)) {
	if f.Present() {
		fn(*f.value)
	}
}
433753
func StoppedFuncTimer(f func()) (t *time.Timer) {
	t = time.AfterFunc(math.MaxInt64, f)
	if !t.Stop() {
		panic("timer already fired")
	}
	return
}
1331219
func Do(threshold time.Duration, sf SlowFunc, cb CallbackFunc) error {
	// Call the slow function
	errCh := make(chan error, 1)
	go func() {
		errCh <- sf()
	}()

	// Wait for it to complete or the threshold to pass
	select {
	case err := <-errCh:
		return err
	case <-time.After(threshold):
		// Threshold reached, call the callback
		cb()
	}

	// Wait an indefinite amount of time for it to finally complete
	return <-errCh
}
722641
func booleanFunc(q query, t iterator) interface{} {
	v := q.Evaluate(t)
	return asBool(t, v)
}
429124
func WithTickInterval(interval time.Duration) Option {
	return func(opts *opts) { opts.tickInterval = interval }
}
1237950
func (f Function) Call(args ...interface{}) error {
	if !f.IsValid() {
		return errors.New("invalid function")
	}
	return f.Caller.Call(args...)
}
644288
func (i Int32) If(fn func(int32)) {
	if i.Present() {
		fn(*i.value)
	}
}