Skip to content

fredmaggiowski/gowq

Repository files navigation

goWQ

Build Go Report Card

A simple work queue manager to schedule jobs and then execute them on a defined pool of goroutines.

It can be used in two modes:

  • static: allows to create a job queue and then run it waiting for all jobs to complete;
  • dynamic: allows to run a job scheduler and then enqueue new jobs while the scheduler runs.

Examples

Static Queue Usage

wq := NewWQ(2)

wq.Push(func(ctx context.Context) error {
    // do something...
    return nil
})
errors := wq.RunAll(context.TODO())

Dynamic Queue Manager

wq := NewWQ(2)

go func(ctx context.Context) {
    wq.Start(ctx)
}(context.TODO())

wq.Schedule(func(ctx context.Context) error {
    // do something...
    return nil
})

// Wait until all jobs have been completed.
_ := wq.Shutdown()

About

A simple and straightforward workqueue manager in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages