當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.NewAsyncTimeoutError函數代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/errors.NewAsyncTimeoutError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewAsyncTimeoutError函數的具體用法?Golang NewAsyncTimeoutError怎麽用?Golang NewAsyncTimeoutError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewAsyncTimeoutError函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: waitForJob

func (gateway Gateway) waitForJob(jobUrl, accessToken string, timeout time.Duration) (err error) {
	startTime := gateway.Clock()
	for true {
		if gateway.Clock().Sub(startTime) > timeout {
			return errors.NewAsyncTimeoutError(jobUrl)
		}
		var request *Request
		request, err = gateway.NewRequest("GET", jobUrl, accessToken, nil)
		response := &JobResource{}
		_, err = gateway.PerformRequestForJSONResponse(request, response)
		if err != nil {
			return
		}

		switch response.Entity.Status {
		case JOB_FINISHED:
			return
		case JOB_FAILED:
			err = errors.New(response.Entity.ErrorDetails.Description)
			return
		}

		accessToken = request.HttpReq.Header.Get("Authorization")

		time.Sleep(gateway.PollingThrottle)
	}
	return
}
開發者ID:palakmathur,項目名稱:cli,代碼行數:28,代碼來源:gateway.go

示例2: waitForJob

func (gateway Gateway) waitForJob(jobURL, accessToken string, timeout time.Duration) error {
	startTime := gateway.Clock()
	for true {
		if gateway.Clock().Sub(startTime) > timeout && timeout != 0 {
			return errors.NewAsyncTimeoutError(jobURL)
		}
		var request *Request
		request, err := gateway.NewRequest("GET", jobURL, accessToken, nil)
		response := &JobResource{}
		_, err = gateway.PerformRequestForJSONResponse(request, response)
		if err != nil {
			return err
		}

		switch response.Entity.Status {
		case JobFinished:
			return nil
		case JobFailed:
			return errors.New(response.Entity.ErrorDetails.Description)
		}

		accessToken = request.HTTPReq.Header.Get("Authorization")

		time.Sleep(gateway.PollingThrottle)
	}
	return nil
}
開發者ID:jsloyer,項目名稱:cli,代碼行數:27,代碼來源:gateway.go

示例3: waitForJob

func waitForJob(jobUrl, accessToken string, timeout time.Duration) (err error) {
	startTime := time.Now()
	for true {
		if time.Now().Sub(startTime) > timeout && timeout != 0 {
			return errors.NewAsyncTimeoutError(jobUrl)
		}
		var request *Request
		request, err = NewRequest("GET", jobUrl, accessToken, nil)
		response := &JobResource{}
		_, err = gwPerformRequestForJSONResponse(request, response)
		if err != nil {
			return
		}

		switch response.Entity.Status {
		case JOB_FINISHED:
			return
		case JOB_FAILED:
			err = errors.New(response.Entity.ErrorDetails.Description)
			return
		}

		accessToken = request.HttpReq.Header.Get("Authorization")

		time.Sleep(DEFAULT_POLLING_THROTTLE)
	}
	return
}
開發者ID:glyn,項目名稱:bloblets,代碼行數:28,代碼來源:abclient.go

示例4:

				})

				AfterEach(func() {
					apiServer.Close()
				})

				It("deletes a resource", func() {
					err := ccGateway.DeleteResource(apiServer.URL, "/v2/foobars/SOME_GUID")
					Expect(err).ToNot(HaveOccurred())
				})

				Context("when the request would take longer than the async timeout", func() {
					It("returns an error", func() {
						apiErr := ccGateway.DeleteResource(apiServer.URL, "/v2/foobars/TIMEOUT")
						Expect(apiErr).To(HaveOccurred())
						Expect(apiErr).To(BeAssignableToTypeOf(errors.NewAsyncTimeoutError("http://some.url")))
					})
				})
			})
		})
	})

	Describe("making an async request", func() {
		var (
			jobStatus     string
			apiServer     *httptest.Server
			authServer    *httptest.Server
			statusChannel chan string
		)

		BeforeEach(func() {
開發者ID:yingkitw,項目名稱:cli,代碼行數:31,代碼來源:gateway_test.go


注:本文中的github.com/cloudfoundry/cli/cf/errors.NewAsyncTimeoutError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。