// Temporary reports whether an operation may succeed if retried.
339519
func (e *OpError) Temporary() bool {
	if ne, ok := e.Err.(*os.SyscallError); ok {
		t, ok := ne.Err.(temporary)
		return ok && t.Temporary()
	}
	t, ok := e.Err.(temporary)
	return ok && t.Temporary()
}
317865
func Remove(tempdir string) error {
	defer func() {
		var k string
		runningMutex.Lock()
		for key, value := range running {
			if value == tempdir {
				k = key
			}
		}
		delete(running, k)
		runningMutex.Unlock()
	}()
	if !strings.HasPrefix(tempdir, os.TempDir()) {
		return errors.New("Remove can only remove temporary directories, tryied to remove " + tempdir)
	}
	path := os.Getenv("PATH")
	index := strings.Index(path, tempdir)
	if index < 0 {
		return fmt.Errorf("%q is not in $PATH", tempdir)
	}
	path = path[:index] + path[index+len(tempdir)+1:]
	err := os.Setenv("PATH", path)
	if err != nil {
		return err
	}
	return os.RemoveAll(tempdir)
}
1066333
func (c *Context) NewTempDir(prefix string) (string, error) {
	t, err := ioutil.TempDir(c.Tmpdir, prefix)
	if err != nil {
		return "", fmt.Errorf("error creating temporary directory: %v", err)
	}
	return t, nil
}
44447
func indefiniteRetry() retry.Iterator {
	return &retry.ExponentialBackoff{
		Limited: retry.Limited{
			Retries: -1,
			Delay:   500 * time.Millisecond,
		},
		MaxDelay: 30 * time.Second,
	}
}
143393
func Retry(ctx context.Context, f func() error) error {
	// container for atomic error value
	type errWrap struct {
		E error
	}

	// Try the function in a goroutine
	var errVal atomic.Value
	doneCh := make(chan struct{})
	go func() {
		defer close(doneCh)

		delay := time.Duration(0)
		for {
			// If our context ended, we want to exit right away.
			select {
			case <-ctx.Done():
				return
			case <-time.After(delay):
			}

			// Try the function call
			err := f()

			// return if we have no error, or a FatalError
			done := false
			switch e := err.(type) {
			case nil:
				done = true
			case Fatal:
				err = e.FatalError()
				done = true
			}

			errVal.Store(errWrap{err})

			if done {
				return
			}

			log.Printf("[WARN] retryable error: %v", err)

			delay *= 2

			if delay == 0 {
				delay = initialBackoffDelay
			}

			if delay > maxBackoffDelay {
				delay = maxBackoffDelay
			}

			log.Printf("[INFO] sleeping for %s", delay)
		}
	}()

	// Wait for completion
	select {
	case <-ctx.Done():
	case <-doneCh:
	}

	var lastErr error
	// Check if we got an error executing
	if ev, ok := errVal.Load().(errWrap); ok {
		lastErr = ev.E
	}

	// Check if we have a context error to check if we're interrupted or timeout
	switch ctx.Err() {
	case context.Canceled:
		return fmt.Errorf("interrupted - last error: %v", lastErr)
	case context.DeadlineExceeded:
		return fmt.Errorf("timeout - last error: %v", lastErr)
	}

	if lastErr != nil {
		return lastErr
	}
	return nil
}
1082181
func Retry(timeout time.Duration, f RetryFunc) error {
	// These are used to pull the error out of the function; need a mutex to
	// avoid a data race.
	var resultErr error
	var resultErrMu sync.Mutex

	c := &StateChangeConf{
		Pending:    []string{"retryableerror"},
		Target:     []string{"success"},
		Timeout:    timeout,
		MinTimeout: 500 * time.Millisecond,
		Refresh: func() (interface{}, string, error) {
			rerr := f()

			resultErrMu.Lock()
			defer resultErrMu.Unlock()

			if rerr == nil {
				resultErr = nil
				return 42, "success", nil
			}

			resultErr = rerr.Err

			if rerr.Retryable {
				return 42, "retryableerror", nil
			}
			return nil, "quit", rerr.Err
		},
	}

	_, waitErr := c.WaitForState()

	// Need to acquire the lock here to be able to avoid race using resultErr as
	// the return value
	resultErrMu.Lock()
	defer resultErrMu.Unlock()

	// resultErr may be nil because the wait timed out and resultErr was never
	// set; this is still an error
	if resultErr == nil {
		return waitErr
	}
	// resultErr takes precedence over waitErr if both are set because it is
	// more likely to be useful
	return resultErr
}
1277306
func (q *Query) RetryPolicy(r RetryPolicy) *Query {
	q.rt = r
	return q
}
764133
func Retry(callback func() error) (err error) {
	for i := 0; ; i++ {
		if err = callback(); err == nil {
			return
		}
		if i >= (defaultRetryAttempts - 1) {
			break
		}
		time.Sleep(defaultRetrySleep)
		log.Error("retrying after error:", err)
	}
	return fmt.Errorf("after %d attempts, last error: %s", defaultRetryAttempts, err)
}
650511
func Retry(attempts int, callback func() error) (err error) {
	return RetryAfter(attempts, callback, 0)
}
473802
func removeTempFile(dir, file string) {
	changeDir(dir)
	if err := os.Remove(file); err != nil {
		beeLogger.Log.Warnf("Could not remove temporary file: %s", err)
	}
}
222404
func (term *Terminal) Reopen() error {
	in := os.Stdin

	t, err := newTerminal(in)
	if err != nil {
		return err
	}

	term.t = t
	return nil
}
232165
func (r *retrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
	// Fail hard on a specific error
	if err == syscall.ECONNREFUSED {
		err = errors.New("Elasticsearch or network down")
		r.logger.Error(err)
		return 0, false, err
	}

	// Stop after n retries
	if retry >= r.retry {
		r.logger.Debugf("Stop retrying after '%d' retries", retry)
		return 0, false, nil
	}

	// Let the backoff strategy decide how long to wait and whether to stop
	r.logger.Debugln("Retry to connect to Elasticsearch")
	wait, stop := r.backoff.Next(retry)
	return wait, stop, nil
}
841225
func (t *Task) SetRetry(d time.Duration) *Task {
	t.retry = d
	return t
}
493576
func (d *TMP006) RawDieTemp() (float64, error) {
	select {
	case temp := <-d.rawDieTemps:
		return temp, nil
	default:
		return d.measureRawDieTemp()
	}
}
277428
func (self *Request) GetTemp(key string, defaultValue interface{}) interface{} {
	if defaultValue == nil {
		panic("*Request.GetTemp()的defaultValue不能为nil，错误位置：key=" + key)
	}
	self.lock.RLock()
	defer self.lock.RUnlock()

	if self.Temp[key] == nil {
		return defaultValue
	}

	if self.TempIsJson[key] {
		return self.Temp.get(key, defaultValue)
	}

	return self.Temp[key]
}
214695
func (fs *fakeFs) TempFile(dir, prefix string) (File, error) {
	file, err := fs.a.TempFile(dir, prefix)
	if err != nil {
		return nil, err
	}
	return &fakeFile{file}, nil
}
893434
func TempFileName(prefix string) (tmp string, err error) {
	tmp, err = RandString(prefix, 20)
	return
}