Skip to content

juwell/parallelworker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parallelworker

this is a simple lib to do work parallel.

for example: you need do some check, called check A, check B, check C, and those check are not interdependent, so we can do those check at the same time

like this

Usage

  1. make a content
ctx := context.Background()
  1. make worker
worker := parallelworker.NewParallelWorker(ctx)
  1. add all your worker
worker.AddWorker(func(ctx context.Context) {
    select {
    	case <-ctx.Done():
            // if ctx is cancel, you should return your function
            return
        default:
    }
    // do something
})
  1. wait for finish

    this function will be blocked, so you need add a timeout context to control it, this context is different from the first one

timeOutCtx := context.WithTimeout(ctx, time.Second * 5)
worker.WaitContext(timeOutCtx)

About

this is a simple lib to do work parallel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages