Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bubble501/taskQueue

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

taskQueue

taskQueue is an task queue for golang. it steal the idea even the code from blog Handling 1 Million Requests per Minute with Go.

The usage of taskQueue is as simple as four steps:

  1. Create your own job struct which implement Execute methods.
  2. Create the queue.
  3. Start the queue.
  4. Add job to the queue.
  5. Waiting for worker to be finished in the main method if it will exit (optional).

Example

import (
	"fmt"
	"github.com/bubble501/taskQueue"
	"testing"
)

type TestJob struct {
	id int
}

func (job TestJob) Execute() {
	total := 0
	for i := 0; i < job.id; i++ {
		total = total + i
	}
	//  fmt.Printf("the total for %d is %d\n", job.id, total)
}

func TestTastQueue(*testing.T) {
	queue := taskQueue.New(8, 2000)
	queue.Start()
	var job taskQueue.Job
	for i := 0; i < 300000; i++ {
		testjob := TestJob{i}
		job = testjob
		queue.AddJob(job)
	}

	queue.Wait()
	fmt.Printf("Finished")
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.