async_task

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 3 Imported by: 1

README

go-async-task

go-async-task is a worker which processes tasks(jobs) asynchronously.

license

Installation

$ go get -u github.com/gjbae1212/go-async-task

Usage

# create worker 
worker, _ := async_task.NewAsyncTask()

# process task asynchronously
_ = worker.AddTask(ctx, task)

LICENSE

This project is following The MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(error)

It is executed if error is raised

type Keeper

type Keeper interface {
	AddTask(ctx context.Context, task Task) error
	UnProcessedTaskSize() int
}

External interface

func NewAsyncTask

func NewAsyncTask(opts ...Option) (Keeper, error)

NewAsyncTask creates an object implemented Keeper interface

type Option

type Option interface {
	// contains filtered or unexported methods
}

type OptionFunc

type OptionFunc func(k *keeper)

func WithErrorHandlerOption

func WithErrorHandlerOption(f ErrorHandler) OptionFunc

WithErrorHandlerOption returns a function which sets handler for the error.

func WithQueueSizeOption

func WithQueueSizeOption(size int) OptionFunc

WithQueueSizeOption returns a function which sets queue size.

func WithTimeoutOption

func WithTimeoutOption(timeout time.Duration) OptionFunc

WithTimeoutOption returns a function which set timeout.

func WithWorkerSizeOption

func WithWorkerSizeOption(size int) OptionFunc

WithWorkerSizeOption returns a function which sets worker size.

type Task

type Task interface {
	Process(ctx context.Context) error
}

It is the task to dealt with

Jump to

Keyboard shortcuts

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