Categorygithub.com/hellodudu/task
repositorypackage
1.4.0
Repository: https://github.com/hellodudu/task.git
Documentation: pkg.go.dev

# README

GoDoc Go Report Card

task

This simple package provides a concurrency and configued tasks handle queue.

Example

// new a tasker with options
tasker := NewTasker(1)
tasker.Init(
    WithStartFns(
			func() {
				fmt.Println("tasker start fn1...")
			},
		),

    WithTimeout(time.Second*5),

    WithSleep(time.Millisecond*100),

    WithUpdateInterval(time.Millisecond*200),

    WithUpdateFn(func() {
        fmt.Println("tasker update...")
    }),
)

// add a simple task
tasker.Add(
    context.Background(),
    func(context.Context, ...interface{}) error {
        fmt.Println("task handled")
    },
)

// add task with parameters
tasker.Add(
    context.Background(),
    func(ctx context.Context, p ...interface{}) error {
        p1 := p[0].(int)
        p2 := p[1].(string)
        fmt.Println("task handled with parameters:", p1, p2)
    },
    1,
    "name",
)

// begin run
go tasker.Run(context.Background())

// stop
tasker.Stop()