Logo

0x5a.live

for different kinds of informations and explorations.

GitHub - shettyh/threadpool: Golang simple thread pool implementation

Golang simple thread pool implementation. Contribute to shettyh/threadpool development by creating an account on GitHub.

Visit SiteGitHub - shettyh/threadpool: Golang simple thread pool implementation

GitHub - shettyh/threadpool: Golang simple thread pool implementation

Golang simple thread pool implementation. Contribute to shettyh/threadpool development by creating an account on GitHub.

Powered by 0x5a.live ๐Ÿ’—

Golang Threadpool implementation

Build Status codecov GoDoc Go Report Card

Scalable threadpool implementation using Go to handle the huge network trafic.

Install

go get github.com/shettyh/threadpool

Usage

Threadpool

  • Implement Runnable interface for tha task that needs to be executed. For example

    type MyTask struct { }
     
    func (t *MyTask) Run(){
      // Do your task here
    }
     
    
  • Create instance of ThreadPool with number of workers required and the task queue size

    pool := threadpool.NewThreadPool(200,1000000)
    
  • Create Task and execute

    task:=&MyTask{}
    err := pool.Execute(task)
    
  • Using Callable task

    type MyTaskCallable struct { }
    
    func (c *MyTaskCallable) Call() interface{} {
      //Do task 
      return result
    }
    
    //Execute callable task
    task := &MyTaskCallable{}
    future, err := pool.ExecuteFuture(task)
    
    //Check if the task is done
    isDone := future.IsDone() // true/false
    
    //Get response , blocking call
    result := future.Get()
    
    
  • Close the pool

    pool.Close()
    

Scheduled threadpool

  • Create instance of ScheduledThreadPool with number of workers required
    schedulerPool:= threadpool.NewScheduledThreadPool(10)
    
  • Create Task and schedule
    task:=&MyTask{}
    pool.ScheduleOnce(task, time.Second*20) // Time delay is in seconds only as of now
    
  • Close the pool
    pool.Close()
    

GoLang Resources

are all listed below.

Resources

listed to get explored on!!

Made with โค๏ธ

to provide different kinds of informations and resources.