// ReadWait sets the amount of time to wait before a websocket read times out.
// It should only be used in the constructor - not Goroutine-safe.
1639
func ReadWait(readWait time.Duration) func(*wsConnection) {
	return func(wsc *wsConnection) {
		wsc.readWait = readWait
	}
}
167007
func (t *timeoutReader) Read(p []byte) (int, error) {
	// FIXME limit the amount of data read in one chunk so as to not exceed the timeout?
	// Do the read in the background
	type result struct {
		n   int
		err error
	}
	done := make(chan result, 1)
	go func() {
		n, err := t.reader.Read(p)
		done <- result{n, err}
	}()
	// Wait for the read or the timeout
	timer := time.NewTimer(t.timeout)
	defer timer.Stop()
	select {
	case r := <-done:
		return r.n, r.err
	case <-timer.C:
		t.cancel()
		return 0, TimeoutError
	}
	panic("unreachable") // for Go 1.0
}
284779
func (f *fen) Wait() (interface{}, error) {
	var (
		pe  PortEvent
		err error
	)
	err = f.cf.portGet(f.p, &pe)
	return pe, err
}
962200
func (s *clientIOSession) ReadTimeout(timeout time.Duration) (interface{}, error) {
	for {
		doRead, msg, err := s.doPreRead()
		if err != nil {
			return nil, err
		}
		if !doRead {
			return msg, nil
		}

		var complete bool
		for {
			if s.in.Readable() > 0 {
				complete, msg, err = s.svr.opts.decoder.Decode(s.in)

				if !complete && err == nil {
					complete, msg, err = s.readFromConn(timeout)
				}
			} else {
				complete, msg, err = s.readFromConn(timeout)
			}

			if nil != err {
				s.in.Clear()
				return nil, err
			}

			if complete {
				break
			}
		}

		if s.in.Readable() == 0 {
			s.in.Clear()
		}

		returnRead, readedMsg, err := s.doPostRead(msg)
		if err != nil {
			return nil, err
		}

		if returnRead {
			return readedMsg, err
		}
	}
}
979470
func (conn *WebsocketConnection) waitForReader() error {
	// no existing readers, wait for one
	for {
		opCode, reader, err := conn.ws.NextReader()
		if err != nil {
			return err
		}

		switch opCode {
		case websocket.BinaryMessage:
			// binary packet
			conn.reader = reader
			return nil

		case websocket.TextMessage:
			// plain text package
			b, err := ioutil.ReadAll(reader)
			if err == nil {
				conn.textChan <- b
			}

		case websocket.PingMessage:
			// receeived a ping, so send a pong
			go func() {
				conn.writeMutex.Lock()
				defer conn.writeMutex.Unlock()
				conn.ws.WriteControl(websocket.PongMessage, []byte{}, time.Now().Add(conn.writeTimeout))
			}()

		case websocket.PongMessage:
			// received a pong, update read deadline
			conn.ws.SetReadDeadline(time.Now().Add(conn.readTimeout))

		case websocket.CloseMessage:
			// received close, so return EOF
			return io.EOF
		}
	}
}
589420
func (cli *Client) waitPacket(packetc <-chan struct{}, timeout time.Duration, errTimeout error) {
	defer cli.conn.wg.Done()

	var timeoutc <-chan time.Time

	if timeout > 0 {
		timeoutc = time.After(timeout * time.Second)
	}

	select {
	case <-packetc:
	case <-timeoutc:
		// Handle the timeout error.
		cli.handleErrorAndDisconn(errTimeout)
	}
}
32430
func (rw *RetryWaiter) calculateWait() time.Duration {
	waitTime := rw.minWait
	if rw.failures > rw.minFailures {
		shift := rw.failures - rw.minFailures - 1
		waitTime = rw.maxWait
		if shift < 31 {
			waitTime = (1 << shift) * time.Second
		}
		if waitTime > rw.maxWait {
			waitTime = rw.maxWait
		}

		if rw.jitter != nil {
			waitTime = rw.jitter.AddJitter(waitTime)
		}
	}

	if waitTime < rw.minWait {
		waitTime = rw.minWait
	}

	return waitTime
}
315024
func (opts *FlushOptions) SetWait(value bool) {
	C.rocksdb_flushoptions_set_wait(opts.c, boolToChar(value))
}
1357490
func (db *DB) compTriggerWait(compC chan<- cCmd) (err error) {
	ch := make(chan error)
	defer close(ch)
	// Send cmd.
	select {
	case compC <- cAuto{ch}:
	case err = <-db.compErrC:
		return
	case <-db.closeC:
		return ErrClosed
	}
	// Wait cmd.
	select {
	case err = <-ch:
	case err = <-db.compErrC:
	case <-db.closeC:
		return ErrClosed
	}
	return err
}
878824
func Wait(t *testing.T, url string, attempts int) {
	ctx := context.Background()

	for a := 0; a < attempts; a++ {
		ctx, cancel := context.WithTimeout(ctx, time.Second)
		defer cancel()

		log.Println("HEAD", url)
		_, err := ctxhttp.Head(ctx, nil, url)
		if err == nil {
			log.Println("Client is ready, beginning test...")
			return
		}

		sleepFor := 100 * time.Millisecond
		log.Println(err, "- sleeping for", sleepFor)
		time.Sleep(sleepFor)
	}

	t.Fatalf("could not talk to client in %d attempts", attempts)
}
299090
func (s *Server) Wait(ctx context.Context) {
	select {
	case <-s.closeContext.Done():
	case <-ctx.Done():
	}
}
8281
func ReadTimeout(reader *bufio.Reader, timeout time.Duration) (*Header, error) {
	type header struct {
		h *Header
		e error
	}
	read := make(chan *header, 1)

	go func() {
		h := &header{}
		h.h, h.e = Read(reader)
		read <- h
	}()

	timer := time.NewTimer(timeout)
	select {
	case result := <-read:
		timer.Stop()
		return result.h, result.e
	case <-timer.C:
		return nil, ErrNoProxyProtocol
	}
}
106051
func (_m *ContainerRuntimeExecutor) WaitInit() error {
	ret := _m.Called()

	var r0 error
	if rf, ok := ret.Get(0).(func() error); ok {
		r0 = rf()
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1265553
func (r *RateLimiter) Wait() {
	for {
		ok, remaining := r.Try()
		if ok {
			break
		}
		time.Sleep(remaining)
	}
}
1224376
func (wg *WaitGroup) Wait() []error {
	wg.wg.Wait()

	wg.mutex.Lock()
	defer wg.mutex.Unlock()

	if len(wg.errs) == 0 {
		return nil
	}
	return wg.errs
}
1078858
func (f *Future) Wait(timeout time.Duration) error {
	select {
	case <-f.completeChannel:
		return nil
	case <-f.cancelChannel:
		return ErrCanceled
	case <-time.After(timeout):
		return ErrTimeout
	}
}
234900
func (cond *Cond) WaitTimeout(mutex *Mutex, ms uint32) error {
	ret := int(C.SDL_CondWaitTimeout(cond.cptr(), mutex.cptr(), C.Uint32(ms)))
	if ret != 0 {
		return GetError()
	}
	return nil
}