Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitWorkers ¶ added in v0.2.0
func InitWorkers(numworkers int, jobs chan PieceOfWork) *sync.WaitGroup
InitWorkers creates a worker pool that execute pieces of work. It is a way of controlling the number go routines to optimize parallelism. It is recommended that this stay around the number of cores unless there is significant blocking time associated with the work involved.
func NewQueue ¶ added in v0.2.0
func NewQueue() chan PieceOfWork
NewQueue creates a bi-directional channel that can take in pieces of work. This is leveraged with the worker pool and is what they pull from while active. The worker pool will end once this channel is closed. The intention is that this channel will be passed into the initialization of the worker pool.
func ReverseBytes ¶ added in v1.7.0
ReverseBytes reverses a byte slice. useful for switching endian-ness
func TimeTrack ¶
TimeTrack is a function that tracks the time spent and outputs specific timing information. This is important for chainquery profiling and is used throughout. It can be reused by just passing `always` as the profile. The basic usage is `defer util.TimeTrack(time.Now(),"<useful identifier>","<profile>")`. This should be placed at the top of the function where time is to be tracked, or at any point where you want to start tracking time.
Types ¶
type PieceOfWork ¶ added in v0.2.0
type PieceOfWork interface { // BeforeExecute will always be executed before the piece of work's execution. BeforeExecute() // Execute is the execution of the actual work. Execute() error // AfterExecute will always be executed after the piece of work's execution if successful. AfterExecute() // OnError will execute in the event an error is returned from the Execute function. OnError(err error) }
PieceOfWork is an interface type for representing a atomic piece of work that can be done independently.