queue

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionPromise

type CompletionPromise struct {
	// contains filtered or unexported fields
}

func NewCompletionPromise

func NewCompletionPromise(timeout time.Duration) *CompletionPromise

func (*CompletionPromise) Wait

func (s *CompletionPromise) Wait() (*types.TxReceipt, error)

Wait is called in order to wait for synchronous transaction completion, rejection, or timeout. When a transaction is committed, a `TxReceipt` is returned. When a transaction is rejected, an error is returned, for example `NotLeaderError`. When wait times out, `TimeoutErr` is returned.

type OneQueueBarrier

type OneQueueBarrier struct {
	// contains filtered or unexported fields
}

OneQueueBarrier is used to synchronize a single producing go-routine and a single consuming go-routine. The producing go-routine enqueues an entry and waits for its consumption to finish. The consuming go-routine dequeues an entry, consumes it, and releases the waiting producing go-routine by sending a reply. Both go-routines are released by closing the OneQueueBarrier.

func NewOneQueueBarrier

func NewOneQueueBarrier(logger *logger.SugarLogger) *OneQueueBarrier

NewOneQueueBarrier creates a new OneQueueBarrier.

func (*OneQueueBarrier) Close

func (qb *OneQueueBarrier) Close() (err error)

Close signals both waiting go-routines to exit and close respective channels.

func (*OneQueueBarrier) Dequeue

func (qb *OneQueueBarrier) Dequeue() (interface{}, error)

Dequeue waits for an entry to be consumed. After consuming the entry is done, the producing go-routine must be release by invoking Reply(). An error is returned if the OneQueueBarrier was closed.

func (*OneQueueBarrier) EnqueueWait

func (qb *OneQueueBarrier) EnqueueWait(entry interface{}) (interface{}, error)

EnqueueWait submits an entry for consumption and ways for a reply, indicating processing had finished. An error is returned if the OneQueueBarrier was closed.

func (*OneQueueBarrier) Reply

func (qb *OneQueueBarrier) Reply(reply interface{}) error

Reply sends a reply to the waiting producing go-routine, thus releasing it. The reply can be nil or an object. An error is returned if the OneQueueBarrier was closed.

type PendingTxs

type PendingTxs struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewPendingTxs

func NewPendingTxs(logger *logger.SugarLogger) *PendingTxs

func (*PendingTxs) Add

func (p *PendingTxs) Add(txID string, promise *CompletionPromise)

func (*PendingTxs) DoneWithReceipt

func (p *PendingTxs) DoneWithReceipt(txIDs []string, blockHeader *types.BlockHeader)

DoneWithReceipt is called after the commit of a block. The `txIDs` slice must be in the same order that transactions appear in the block.

func (*PendingTxs) Empty

func (p *PendingTxs) Empty() bool

func (*PendingTxs) Has

func (p *PendingTxs) Has(txID string) bool

func (*PendingTxs) ReleaseWithError

func (p *PendingTxs) ReleaseWithError(txIDs []string, err error)

ReleaseWithError is called when block replication fails with an error, typically NotLeaderError. This may come from the block replicator or the block creator. The `txIDs` slice does not have to be in the same order that transactions appear in the block.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is queue data structure implemented using go channels

func New

func New(size uint32) *Queue

New creates a new queue of given size

func (*Queue) Capacity

func (q *Queue) Capacity() int

Capacity returns the max size of the queue

func (*Queue) Close

func (q *Queue) Close()

Close drops all items in the queue and closes it

func (*Queue) Dequeue

func (q *Queue) Dequeue() interface{}

Dequeue removes and returns an entry from the head of the queue

func (*Queue) DequeueWithWaitLimit

func (q *Queue) DequeueWithWaitLimit(d time.Duration) interface{}

DequeueWithWaitLimit waits for the specified duration to dequeue an entry from the queue. If the queue has been empty for the specified duration, it will return nil

func (*Queue) Enqueue

func (q *Queue) Enqueue(entry interface{})

Enqueue adds the entry to the tail of the queue

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty returns true if the queue is empty

func (*Queue) IsFull

func (q *Queue) IsFull() bool

IsFull returns true if the queue is full

func (*Queue) Size

func (q *Queue) Size() int

Size returns the size of the queue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL