// HandleContext works the same as Handle, but takes a context that will
// exit the handler loop when canceled/timed out.
501422
func HandleContext(ctx context.Context, handler Handler) {
	format, _ := os.LookupEnv("FN_FORMAT")
	if format != "" && format != "http-stream" {
		log.Fatal("only http-stream format is supported, please set function.format=http-stream against your fn service")
	}
	path := os.Getenv("FN_LISTENER")
	startHTTPServer(ctx, handler, path)
}
1186722
func (c *TasksListCall) Context(ctx context.Context) *TasksListCall {
	c.ctx_ = ctx
	return c
}
757349
func (r *Report) AddContext(k string, v interface{}) {
	r.Request.Context[k] = v
}
41017
func ContextHandlerFunc(h http.HandlerFunc, cap int) http.HandlerFunc {
	return ContextHandler(h, cap)
}
28375
func AddContext(err error, context string) error {
	if err == nil {
		return nil
	}
	return Extend(err, New(context))
}
123129
func (c *GetRefConfigsCall) Context(ctx context.Context) *GetRefConfigsCall {
	c.ctx_ = ctx
	return c
}
560340
func (c *AckCall) Context(ctx context.Context) *AckCall {
	c.ctx_ = ctx
	return c
}
1061097
func (c *ResetCall) Context(ctx context.Context) *ResetCall {
	c.ctx_ = ctx
	return c
}
189804
func (c *GetTaskDefCall) Context(ctx context.Context) *GetTaskDefCall {
	c.ctx_ = ctx
	return c
}
1301033
func (session *Session) WithContext(ctx context.Context) *Session {
	s := *session
	s.context = ctx
	return &s
}
1109129
func (process *TeleportProcess) WaitWithContext(ctx context.Context) {
	local, cancel := context.WithCancel(ctx)
	go func() {
		defer cancel()
		process.Supervisor.Wait()
	}()
	select {
	case <-local.Done():
		return
	}
}
30692
func ContextHandler(h http.Handler, cap int) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if _, ok := GetContext(w); ok {
			// Self-awareness, context handler is already set up
			h.ServeHTTP(w, r)
			return
		}

		// Create the context-providing ResponseWriter replacement.
		ctxw := &contextResponseWriter{
			w,
			make(map[interface{}]interface{}, cap),
		}
		// Call the wrapped handler with the context-aware writer
		h.ServeHTTP(ctxw, r)
	}
}
1131655
func (c *GroupDeleteCall) Context(ctx context.Context) *GroupDeleteCall {
	c.ctx_ = ctx
	return c
}
844397
func (c *GetConfigByHashCall) Context(ctx context.Context) *GetConfigByHashCall {
	c.ctx_ = ctx
	return c
}
1070042
func (h *Recovery) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) (err error) {
	ctx = reporter.WithReporter(ctx, h.Reporter)

	// Add the request to the context.
	ctx = errors.WithRequest(ctx, r)

	// Add the request id
	ctx = errors.WithInfo(ctx, "request_id", httpx.RequestID(ctx))

	defer func() {
		if e := errors.Recover(ctx, recover()); e != nil {
			w.WriteHeader(http.StatusInternalServerError)
			err = e
			reporter.Report(ctx, err)
			return
		}
	}()

	err = h.handler.ServeHTTPContext(ctx, w, r)

	return
}
474517
func (c *PutBatchCall) Context(ctx context.Context) *PutBatchCall {
	c.ctx_ = ctx
	return c
}
1366529
func (c *TasksNewCall) Context(ctx context.Context) *TasksNewCall {
	c.ctx_ = ctx
	return c
}