// Do repeatedly executes an operation until no error condition occurs or the
// given timeout is reached, whatever comes first.
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
			}
		}
	}
}
97514
func (sf SenderFunc) Do(r *http.Request) (*http.Response, error) {
	return sf(r)
}
502900
func (ix *Reindexer) Do() (*ReindexerResponse, error) {
	if ix.sourceClient == nil {
		return nil, errors.New("no source client")
	}
	if ix.sourceIndex == "" {
		return nil, errors.New("no source index")
	}
	if ix.targetClient == nil {
		ix.targetClient = ix.sourceClient
	}
	if ix.scanFields == nil {
		ix.scanFields = []string{"_source", "_parent", "_routing"}
	}
	if ix.bulkSize <= 0 {
		ix.bulkSize = 500
	}
	if ix.scroll == "" {
		ix.scroll = "5m"
	}

	// Count total to report progress (if necessary)
	var err error
	var current, total int64
	if ix.progress != nil {
		total, err = ix.count()
		if err != nil {
			return nil, err
		}
	}

	// Prepare scan and scroll to iterate through the source index
	scanner := ix.sourceClient.Scan(ix.sourceIndex).Scroll(ix.scroll).Fields(ix.scanFields...)
	if ix.query != nil {
		scanner = scanner.Query(ix.query)
	}
	if ix.size > 0 {
		scanner = scanner.Size(ix.size)
	}
	cursor, err := scanner.Do()

	bulk := ix.targetClient.Bulk()

	ret := &ReindexerResponse{
		Errors: make([]*BulkResponseItem, 0),
	}

	// Main loop iterates through the source index and bulk indexes into target.
	for {
		docs, err := cursor.Next()
		if err == EOS {
			break
		}
		if err != nil {
			return ret, err
		}

		if docs.TotalHits() > 0 {
			for _, hit := range docs.Hits.Hits {
				if ix.progress != nil {
					current++
					ix.progress(current, total)
				}

				err := ix.reindexerFunc(hit, bulk)
				if err != nil {
					return ret, err
				}

				if bulk.NumberOfActions() >= ix.bulkSize {
					bulk, err = ix.commit(bulk, ret)
					if err != nil {
						return ret, err
					}
				}
			}
		}
	}

	// Final flush
	if bulk.NumberOfActions() > 0 {
		bulk, err = ix.commit(bulk, ret)
		if err != nil {
			return ret, err
		}
		bulk = nil
	}

	return ret, nil
}
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
}
705197
func Do(req *http.Request) (resp *http.Response, err error) {
	c := New()
	return c.Do(req)
}
982860
func (c *Client) Do(ctx context.Context, req *APIRequest, v interface{}, responseType string) (*APIResponse, error) {
	var err error
	var resp *http.Response

	req.HTTP = req.HTTP.WithContext(ctx)

	if resp, err = c.client.Do(req.HTTP); err != nil {
		return nil, err
	}

	r := &APIResponse{
		Request: req,
		HTTP:    resp,
	}

	if v != nil {
		if r.Body, err = readDoResponseBody(v, &r.HTTP.Body, responseType); err != nil {
			return nil, err
		}
	}

	if err = CheckResponse(r); err != nil {
		return r, err
	}

	return r, err
}
267326
func (c *Client) Do(req *http.Request) (*http.Response, error) {
	do := func(args ...interface{}) (*http.Response, error) {
		return c.HTTPClient.Do(args[0].(*http.Request))
	}

	resp, err := c.HTTPClient.Do(req)
	if err != nil {
		if c.ExponentialBackoff {
			return c.backoff(do, req)
		}
		return nil, err
	}

	if resp.StatusCode >= http.StatusInternalServerError && c.ExponentialBackoff {
		return c.backoff(do, req)
	}

	return resp, err
}
749201
func (s *CountService) Do() (int64, error) {
	// Check pre-conditions
	if err := s.Validate(); err != nil {
		return 0, err
	}

	// Get URL for request
	path, params, err := s.buildURL()
	if err != nil {
		return 0, err
	}

	// Setup HTTP request body
	var body interface{}
	if s.query != nil {
		query := make(map[string]interface{})
		query["query"] = s.query.Source()
		body = query
	} else if s.bodyJson != nil {
		body = s.bodyJson
	} else if s.bodyString != "" {
		body = s.bodyString
	}

	// Get HTTP response
	res, err := s.client.PerformRequest("POST", path, params, body)
	if err != nil {
		return 0, err
	}

	// Return result
	ret := new(CountResponse)
	if err := json.Unmarshal(res.Body, ret); err != nil {
		return 0, err
	}
	if ret != nil {
		return ret.Count, nil
	}

	return int64(0), nil
}
1036071
func (rt *DefaultRequestDoer) Do(ctx context.Context, r *http.Request,
	v interface{}) (*http.Response, error) {

	resp, err := rt.Client.Do(r)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	err = checkResponseCode(resp)
	if err != nil {
		return resp, err
	}

	if v != nil {
		dec := json.NewDecoder(resp.Body)
		err = dec.Decode(v)
		if err != nil {
			return nil, err
		}
	}

	return resp, nil
}
119577
func (c *Client) Do(req *http.Request) (*http.Response, error) {
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return nil, err
	}

	return resp, nil
}
1337621
func (c *Client) do(req *http.Request, v interface{}) (*http.Response, error) {
	resp, err := c.client.Do(req)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	if status := resp.StatusCode; status < 200 || status > 299 {
		return resp, RegistryError{Code: status, method: req.Method, url: req.URL}
	}

	if v != nil {
		if writer, ok := v.(io.Writer); ok {
			io.Copy(writer, resp.Body)
		} else {
			err = json.NewDecoder(resp.Body).Decode(v)
		}
	}

	return resp, err
}
365447
func (s *PingService) Do(ctx context.Context) (*PingResult, int, error) {
	s.client.mu.RLock()
	basicAuth := s.client.basicAuth
	basicAuthUsername := s.client.basicAuthUsername
	basicAuthPassword := s.client.basicAuthPassword
	s.client.mu.RUnlock()

	url_ := s.url + "/"

	params := make(url.Values)
	if s.timeout != "" {
		params.Set("timeout", s.timeout)
	}
	if s.pretty {
		params.Set("pretty", "true")
	}
	if len(params) > 0 {
		url_ += "?" + params.Encode()
	}

	var method string
	if s.httpHeadOnly {
		method = "HEAD"
	} else {
		method = "GET"
	}

	// Notice: This service must NOT use PerformRequest!
	req, err := NewRequest(method, url_)
	if err != nil {
		return nil, 0, err
	}

	if basicAuth {
		req.SetBasicAuth(basicAuthUsername, basicAuthPassword)
	}

	res, err := s.client.c.Do((*http.Request)(req).WithContext(ctx))
	if err != nil {
		return nil, 0, err
	}
	defer res.Body.Close()

	var ret *PingResult
	if !s.httpHeadOnly {
		ret = new(PingResult)
		if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
			return nil, res.StatusCode, err
		}
	}

	return ret, res.StatusCode, nil
}
642096
func (s *SearchService) Do(ctx context.Context) (*SearchResult, error) {
	// Check pre-conditions
	if err := s.Validate(); err != nil {
		return nil, err
	}

	// Get URL for request
	path, params, err := s.buildURL()
	if err != nil {
		return nil, err
	}

	// Perform request
	var body interface{}
	if s.source != nil {
		body = s.source
	} else {
		src, err := s.searchSource.Source()
		if err != nil {
			return nil, err
		}
		body = src
	}
	res, err := s.client.PerformRequest(ctx, PerformRequestOptions{
		Method:          "POST",
		Path:            path,
		Params:          params,
		Body:            body,
		MaxResponseSize: s.maxResponseSize,
	})
	if err != nil {
		return nil, err
	}

	// Return search results
	ret := new(SearchResult)
	if err := s.client.decoder.Decode(res.Body, ret); err != nil {
		return nil, err
	}
	return ret, nil
}
1297472
func Do(method, url string, v ...interface{}) (*Resp, error) {
	return std.Do(method, url, v...)
}
1000198
func (c *ClusterClient) Do(args ...interface{}) *Cmd {
	cmd := NewCmd(args...)
	c.Process(cmd)
	return cmd
}
381385
func (p *pool) do(kind int, resp *resp) (*resp, error) {
	request := &poolRequest{
		kind:         kind,
		resp:         resp,
		responseChan: make(chan *poolResponse, 1),
	}
	p.requestChan <- request
	response := <-request.responseChan
	return response.resp, response.err
}
1306398
func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
	httpResp, err := c.client.Do(req)
	if err != nil {
		return nil, err
	}

	err = CheckResponse(httpResp)
	if err != nil {
		// Even though there was an error, we still return the response
		// in case the caller wants to inspect it further
		return newResponse(httpResp, nil), err
	}

	if v != nil {
		// Open a NewDecoder and defer closing the reader only if there is a provided interface to decode to
		defer httpResp.Body.Close()
		err = json.NewDecoder(httpResp.Body).Decode(v)
	}

	resp := newResponse(httpResp, v)
	return resp, err
}