util

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseRows added in v0.2.0

func CloseRows(rows *sql.Rows)

CloseRows Closes SQL Rows for custom SQL queries.

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 Min

func Min(x, y int) int

Min is a helpful function to take the min between two integers.

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

func ReverseBytes(b []byte) []byte

ReverseBytes reverses a byte slice. useful for switching endian-ness

func TimeTrack

func TimeTrack(start time.Time, name string, profile string)

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.

Jump to

Keyboard shortcuts

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