Documentation ¶
Overview ¶
This package aim to simplify goroutine management you can run goroutine and get result from it without make [channel](https://golang.org/doc/effective_go.html#channels) or use [waitgroup](https://golang.org/pkg/sync/#WaitGroup). Just define the function and let this package handle the rest for you
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResultBool ¶
ResultBool parse asynctask runner result to bool return error if actual result is not bool
func ResultInt ¶
ResultInt parse asynctask runner result to int return error if actual result is not int
func ResultObj ¶
func ResultObj(i interface{}, o interface{}) error
ResultObj parse asynctask runner result to destination interface return error if actual result schema and destination schema is not match
func ResultString ¶
ResultString parse asynctask runner result to string return error if actual result is not string
Types ¶
type BaseAsyncTask ¶ added in v1.1.0
type BaseAsyncTask struct {
// contains filtered or unexported fields
}
BaseAsyncTask hold the base context for asynctask
func NewAsyncTask ¶ added in v1.1.0
func NewAsyncTask(ctx context.Context) *BaseAsyncTask
NewAsyncTask create new asynctask runner instance
func (*BaseAsyncTask) CancelOnError ¶ added in v1.1.0
func (b *BaseAsyncTask) CancelOnError(flag bool) *BaseAsyncTask
CancelOnError is to flag if an error happen, immediately return or not
func (*BaseAsyncTask) GetResult ¶ added in v1.1.0
func (b *BaseAsyncTask) GetResult(id string) interface{}
GetResult is to get result from asynctask by ID
func (*BaseAsyncTask) NewRunner ¶ added in v1.1.0
func (b *BaseAsyncTask) NewRunner() *Runner
NewRunner create new asynctask runner
func (*BaseAsyncTask) SetRunnerPoolSize ¶ added in v1.1.0
func (b *BaseAsyncTask) SetRunnerPoolSize(size int) *BaseAsyncTask
SetRunnerPoolSize to set max goroutine can run at the same time goroutine will run as soon as the pool worker ready
func (*BaseAsyncTask) StartAndWait ¶ added in v1.1.0
func (b *BaseAsyncTask) StartAndWait() error
StartAndWait start the asynctask and wait for all task finish
type Runner ¶ added in v1.1.0
type Runner struct {
// contains filtered or unexported fields
}
Runner hold the base context for asynctask runner
func (*Runner) SetMultiple ¶ added in v1.1.0
SetMultiple is to set asynctask runner can run multiple times on same ID if runner is set to multiple, the result will become slice of interface