// WaitAuthorization polls an authorization at the given URL
// until it is in one of the final states, StatusValid or StatusInvalid,
// or the context is done.
//
// It returns a non-nil Authorization only if its Status is StatusValid.
// In all other cases WaitAuthorization returns an error.
// If the Status is StatusInvalid, the returned error is ErrAuthorizationFailed.
WaitAuthorization polls an authorization at the given URL
until it is in one of the final states, StatusValid or StatusInvalid,
or the context is done.

It returns a non-nil Authorization only if its Status is StatusValid.
In all other cases WaitAuthorization returns an error.
If the Status is StatusInvalid, the returned error is ErrAuthorizationFailed.
// WaitAuthorization polls an authorization at the given URL // until it is in one of the final states StatusValid or StatusInvalid // or the context is done . // // It returns a non - nil Authorization only if its Status is StatusValid . // In all other cases WaitAuthorization returns an error . // If the Status is StatusInvalid the returned error is ErrAuthorizationFailed .
func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorization, error) {
	var count int
	sleep := func(v string, inc int) error {
		count += inc
		d := backoff(count, 10*time.Second)
		d = retryAfter(v, d)
		wakeup := time.NewTimer(d)
		defer wakeup.Stop()
		select {
		case <-ctx.Done():
			return ctx.Err()
		case <-wakeup.C:
			return nil
		}
	}
	for {
		res, err := c.get(ctx, url)
		if err != nil {
			return nil, err
		}
		retry := res.Header.Get("retry-after")
		if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusAccepted {
			res.Body.Close()
			if err := sleep(retry, 1); err != nil {
				return nil, err
			}
			continue
		}
		var raw wireAuthz
		err = json.NewDecoder(res.Body).Decode(&raw)
		res.Body.Close()
		if err != nil {
			if err := sleep(retry, 0); err != nil {
				return nil, err
			}
			continue
		}
		if raw.Status == StatusValid {
			return raw.authorization(url), nil
		}
		if raw.Status == StatusInvalid {
			return nil, ErrAuthorizationFailed
		}
		if err := sleep(retry, 0); err != nil {
			return nil, err
		}
	}
}
func ( c * Client ) WaitAuthorization ( ctx context . Context , url string ) ( * Authorization , error ) { var count int sleep := func ( v string , inc int ) error { count += inc d := backoff ( count , 10 * time . Second ) d = retryAfter ( v , d ) wakeup := time . NewTimer ( d ) defer wakeup . Stop ( ) select { case <- ctx . Done ( ) : return ctx . Err ( ) case <- wakeup . C : return nil } } for { res , err := c . get ( ctx , url ) if err != nil { return nil , err } retry := res . Header . Get ( " " ) if res . StatusCode != http . StatusOK && res . StatusCode != http . StatusAccepted { res . Body . Close ( ) if err := sleep ( retry , 1 ) ; err != nil { return nil , err } continue } var raw wireAuthz err = json . NewDecoder ( res . Body ) . Decode ( & raw ) res . Body . Close ( ) if err != nil { if err := sleep ( retry , 0 ) ; err != nil { return nil , err } continue } if raw . Status == StatusValid { return raw . authorization ( url ) , nil } if raw . Status == StatusInvalid { return nil , ErrAuthorizationFailed } if err := sleep ( retry , 0 ) ; err != nil { return nil , err } } }
WaitAuthorization polls an authorization at the given URL
until it is in one of the final states, StatusValid or StatusInvalid,
or the context is done.
WaitAuthorization polls an authorization at the given URL until it is in one of the final states StatusValid or StatusInvalid or the context is done .