// NewEventBusWithBufferCapacity returns a new event bus with the given buffer capacity.
436047
func NewEventBusWithBufferCapacity(cap int) *EventBus {
	// capacity could be exposed later if needed
	pubsub := tmpubsub.NewServer(tmpubsub.BufferCapacity(cap))
	b := &EventBus{pubsub: pubsub}
	b.BaseService = *cmn.NewBaseService(nil, "EventBus", b)
	return b
}
1326960
func NewResultBuffer(ctx *plan.Context, writeTo *[]schema.Message) *ResultBuffer {
	m := &ResultBuffer{
		TaskBase: NewTaskBase(ctx),
	}
	m.Handler = func(ctx *plan.Context, msg schema.Message) bool {
		*writeTo = append(*writeTo, msg)
		//u.Infof("write to msgs: %v", len(*writeTo))
		return true
	}
	return m
}
1259026
func (lib *Lib) MakeBuffer(alloc int) (*Buffer, error) {
	s := C.malloc(C.gss_buffer_size)
	if s == nil {
		return nil, ErrMallocFailed
	}
	C.memset(s, 0, C.gss_buffer_size)

	b := &Buffer{
		Lib:            lib,
		C_gss_buffer_t: C.gss_buffer_t(s),
		alloc:          alloc,
	}
	return b, nil
}
211271
func (pool *ByteBlockPool) NextBuffer() {
	if 1+pool.bufferUpto == len(pool.Buffers) {
		newBuffers := make([][]byte, Oversize(len(pool.Buffers)+1, NUM_BYTES_OBJECT_REF))
		copy(newBuffers, pool.Buffers)
		pool.Buffers = newBuffers
	}
	pool.Buffer = pool.allocator.allocate()
	pool.Buffers[1+pool.bufferUpto] = pool.Buffer
	pool.bufferUpto++

	pool.ByteUpto = 0
	pool.ByteOffset += BYTE_BLOCK_SIZE
}
11955
func (d *Context) ResizeBuffer(index int, newSize int) unsafe.Pointer {
	return C.duk_resize_buffer(d.duk_context, C.duk_idx_t(index), C.duk_size_t(newSize))
}
251312
func NewEventHandler(saga Saga, commandHandler eh.CommandHandler) *EventHandler {
	return &EventHandler{
		saga:           saga,
		commandHandler: commandHandler,
	}
}
219163
func newBufferedReadSeeker(readSeeker io.ReadSeeker, size int) bufferedReadSeeker {
	return bufferedReadSeeker{
		r: bufio.NewReaderSize(readSeeker, size),
		s: readSeeker,
	}
}
62996
func NewEventer() Eventer {
	evtr := &eventer{
		eventnames: make(map[string]string),
		in:         make(eventChannel, eventChanBufferSize),
		outs:       make(map[eventChannel]eventChannel),
	}

	// goroutine to cascade "in" events to all "out" event channels
	go func() {
		for {
			select {
			case evt := <-evtr.in:
				evtr.eventsMutex.Lock()
				for _, out := range evtr.outs {
					out <- evt
				}
				evtr.eventsMutex.Unlock()
			}
		}
	}()

	return evtr
}
62462
func newBufferWithCap(initialCap int) *bytes.Buffer {
	initialBuf := make([]byte, 0, initialCap)
	return bytes.NewBuffer(initialBuf)
}
1303485
func NewRingBuffer(
	capacity int,
	consolidateFunc MsgConsolidateFunc) *RingBuffer {
	return &RingBuffer{
		consolidateFunc: consolidateFunc,
		next:            0,
		msgs:            make([]Msg, capacity),
	}
}
1218655
func NewBufferWriter(w io.WriteCloser) *BufferWriter {
	return &BufferWriter{
		W: w,
		H: make(http.Header),
	}
}
632494
func (b *EventBus) SubscribeUnbuffered(ctx context.Context, subscriber string, query tmpubsub.Query) (Subscription, error) {
	return b.pubsub.SubscribeUnbuffered(ctx, subscriber, query)
}
824986
func newBuffer(br *Reader) (*buffer, error) {
	n, err := io.ReadFull(br.r, br.buf[:4])
	// br.r.Chunk() is only valid after the call the Read(), so this
	// must come after the first read in the record.
	tx := br.r.Begin()
	defer func() {
		br.lastChunk = tx.End()
	}()
	if err != nil {
		return nil, err
	}
	if n != 4 {
		return nil, errors.New("bam: invalid record: short block size")
	}
	b := &buffer{data: br.buf[:4]}
	size := int(b.readInt32())
	if size == 0 {
		return nil, io.EOF
	}
	if size < 0 {
		return nil, errors.New("bam: invalid record: invalid block size")
	}
	b.off, b.data = 0, make([]byte, size)
	n, err = io.ReadFull(br.r, b.data)
	if err != nil {
		return nil, err
	}
	if n != size {
		return nil, errors.New("bam: truncated record")
	}
	return b, nil
}
941263
func NewEventHandler(eventHandler eh.EventHandler) *EventHandler {
	h := &EventHandler{
		EventHandler: eventHandler,
		eventsCh:     make(chan data),
		errCh:        make(chan error, 1),
	}

	go h.run()

	return h
}
750280
func NewEventStream() *EventStream {
	return &EventStream{
		mutex:     new(sync.Mutex),
		receivers: make(map[net.Conn]*EventReceiver),
	}
}
810116
func NewBuffer(size int64) (*Buffer, error) {
	if size <= 0 {
		return nil, fmt.Errorf("Size must be positive")
	}

	b := &Buffer{
		size: size,
		data: make([]byte, size),
	}
	return b, nil
}
105082
func BytesBuffer() *bytes.Buffer {
	buf := bytesBuffer.Get().(*bytes.Buffer)
	buf.Reset()
	return buf
}