Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrQueueFull = fmt.Errorf("queue is full, not able add the task")
)
Functions ¶
This section is empty.
Types ¶
type Callable ¶
type Callable interface {
Call() interface{}
}
Callable the tasks which returns the output after exit should implement this interface
type Future ¶
type Future struct {
// contains filtered or unexported fields
}
Future is the handle returned after submitting a callable task to the thread threadpool
type Runnable ¶
type Runnable interface {
Run()
}
Runnable is interface for the jobs that will be executed by the threadpool
type ScheduledThreadPool ¶
type ScheduledThreadPool struct {
// contains filtered or unexported fields
}
ScheduledThreadPool Schedules the task with the given delay
func NewScheduledThreadPool ¶
func NewScheduledThreadPool(noOfWorkers int) *ScheduledThreadPool
NewScheduledThreadPool creates new scheduler thread threadpool with given number of workers
func (*ScheduledThreadPool) Close ¶
func (stf *ScheduledThreadPool) Close()
Close will close the thread threadpool TODO: check the existing task before closing
func (*ScheduledThreadPool) ScheduleOnce ¶
func (stf *ScheduledThreadPool) ScheduleOnce(task Runnable, delay time.Duration)
ScheduleOnce the task with given delay
type ThreadPool ¶
type ThreadPool struct {
// contains filtered or unexported fields
}
ThreadPool type for holding the workers and handle the job requests
func NewThreadPool ¶
func NewThreadPool(noOfWorkers int, queueSize int64) *ThreadPool
NewThreadPool creates thread threadpool
func (*ThreadPool) Close ¶
func (t *ThreadPool) Close()
Close will close the threadpool It sends the stop signal to all the worker that are running TODO: need to check the existing /running task before closing the threadpool
func (*ThreadPool) Execute ¶
func (t *ThreadPool) Execute(task Runnable) error
Execute submits the job to available worker
func (*ThreadPool) ExecuteFuture ¶
func (t *ThreadPool) ExecuteFuture(task Callable) (*Future, error)
ExecuteFuture will submit the task to the threadpool and return the response handle