// Create a new context.
//
// The argument specifies the size of the ØMQ thread pool to handle I/O operations.
// If your application is using only the inproc transport for messaging you may set
// this to zero, otherwise set it to at least one.
493778
func NewContext(nr_of_threads int) (ctx *Context, err error) {
	if initVersionError != nil {
		return nil, initVersionError
	}
	ctx = &Context{}
	c, e := C.zmq_init(C.int(nr_of_threads))
	if c == nil {
		err = errget(e)
		ctx.err = err
	} else {
		ctx.ctx = c
		ctx.opened = true
		ctx.nr_of_threads = nr_of_threads
		runtime.SetFinalizer(ctx, (*Context).Term)
	}
	return
}
1235036
func (w *Ware) CreateContext() *context {
	c := &context{inject.New(), w.handlers, w.action, nil, 0}
	c.SetParent(w)
	c.MapTo(c, (*Context)(nil))
	return c
}
1043377
func (c *GroupRolloutActiveSetCall) Context(ctx context.Context) *GroupRolloutActiveSetCall {
	c.ctx_ = ctx
	return c
}
386351
func (c *BotsDimensionsCall) Context(ctx context.Context) *BotsDimensionsCall {
	c.ctx_ = ctx
	return c
}
1091542
func (driver *MesosSchedulerDriver) context() context.Context {
	// set a "session" attribute so that the messenger can see it
	// and use it for reporting delivery errors.
	return sessionid.NewContext(context.TODO(), driver.connection.String())
}
967112
func (c *SucceedCall) Context(ctx context.Context) *SucceedCall {
	c.ctx_ = ctx
	return c
}
1121474
func (c *ChannelPublicListCall) Context(ctx context.Context) *ChannelPublicListCall {
	c.ctx_ = ctx
	return c
}
483871
func (c *StartCall) Context(ctx context.Context) *StartCall {
	c.ctx_ = ctx
	return c
}
480473
func (c *TasksCountCall) Context(ctx context.Context) *TasksCountCall {
	c.ctx_ = ctx
	return c
}
681151
func (c *GroupPatchCall) Context(ctx context.Context) *GroupPatchCall {
	c.ctx_ = ctx
	return c
}
317886
func (c *SetNextBuildNumberCall) Context(ctx context.Context) *SetNextBuildNumberCall {
	c.ctx_ = ctx
	return c
}
474517
func (c *PutBatchCall) Context(ctx context.Context) *PutBatchCall {
	c.ctx_ = ctx
	return c
}
53931
func (c *TaskResultCall) Context(ctx context.Context) *TaskResultCall {
	c.ctx_ = ctx
	return c
}
797920
func (c *UpstreamListCall) Context(ctx context.Context) *UpstreamListCall {
	c.ctx_ = ctx
	return c
}
1031287
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *Conn, err error) {
	if ctx == nil {
		panic("nil Context")
	}

	c := &Conn{
		pending: make(map[uint64]*rpcCall),
		streams: make(map[string]*streamClients),
	}
	c.ctx, c.cancel = context.WithCancel(context.Background())

	defer func() {
		select {
		case <-ctx.Done():
			conn, err = nil, ctx.Err()
		default:
		}
		if err != nil {
			c.Close()
		}
	}()

	for _, o := range opts {
		o(&c.dialOpts)
	}

	netDial := c.dialOpts.dialer
	if netDial == nil {
		netDial = func(ctx context.Context, addr string) (io.ReadWriteCloser, error) {
			ws := &c.dialOpts.wsDialer

			if ws.WriteBufferSize == 0 {
				// Set the default size for use in writeLimiter.
				ws.WriteBufferSize = defaultWriteBufferSize
			}

			// Set NetDial to dial with context, this action will
			// override the HandshakeTimeout setting.
			ws.NetDial = func(network, addr string) (net.Conn, error) {
				conn, err := (&net.Dialer{}).DialContext(ctx, network, addr)
				// Use writeLimiter to avoid writing fragmented
				// websocket messages. We're not accounting for
				// the header length here because it varies, as
				// a result we might block some valid writes
				// that are a few bytes too large.
				return &writeLimiter{
					limit: ws.WriteBufferSize,
					Conn:  conn,
				}, err
			}

			wsConn, _, err := ws.Dial(addr, nil)
			if err != nil {
				return nil, err
			}

			if ws.EnableCompression {
				c.compressionLevel = wsConn.SetCompressionLevel
			}

			return &wsReadWriteCloser{wsConn: wsConn}, nil
		}
	}

	c.conn, err = netDial(ctx, target)
	if err != nil {
		return nil, err
	}
	newCodec := c.dialOpts.codec
	if newCodec == nil {
		newCodec = func(conn io.ReadWriter) Codec {
			return &jsonCodec{
				enc: json.NewEncoder(conn),
				dec: json.NewDecoder(conn),
			}
		}
	}
	c.codec = newCodec(c.conn)

	recvDone := func(err error) {
		// When we receive Inspector.detached the remote will close
		// the connection afterwards and recvDone will return. Maybe
		// we could give the user time to react to the event before
		// closing?
		// TODO(mafredri): Do we want to close here, like this?
		c.close(err)
	}
	go c.recv(c.notify, recvDone)

	return c, nil
}
959472
func (o *MultiAuthExampleAPI) Context() *middleware.Context {
	if o.context == nil {
		o.context = middleware.NewRoutableContext(o.spec, o, nil)
	}

	return o.context
}
707329
func (c *GetProjectsCall) Context(ctx context.Context) *GetProjectsCall {
	c.ctx_ = ctx
	return c
}