Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrRunnerClosed = errors.New("runner is closed") ErrRunnerAlreadyClosed = errors.New("runner is already closed") )
Functions ¶
func NewMergedContext ¶ added in v0.0.2
NewMergedContext returns a new context that merges two contexts.
func WithBufferSize ¶
func WithBufferSize(bufferSize int) runnerOpt
WithBufferSize sets the buffer size of the tasks channel. if the buffer size is less than 0, it will be set to 1.
func WithWorkerSize ¶
func WithWorkerSize(worker int) runnerOpt
WithWorkerSize sets the number of workers that will be used to execute the submitted tasks. if the worker size is less than or equal to 0, it will be set to 1.
Types ¶
type Future ¶
Future represents a task that will be executed in the future. The Await function will block until the task is completed. If the context passed to the Await function is canceled, the Await function will return but the task will still be executed. if the task needs to be canceled, the context passed to the Submit function should be canceled.
type Runner ¶
type Runner interface { // Submit a task to be executed by the runner's workers. the context passed to the Submit function will be merged with the runner's context. // and the merged context will be passed to the submitted function. This ensures that if the runner is closed, the submitted function will // be canceled. Submit(ctx context.Context, fn func(context.Context) error) Future // Close the runner and wait for all the submitted tasks to be completed. // Calling this function again after closure will return ErrRunnerAlreadyClosed. Close(ctx context.Context) error }