Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
35
pkg/utils/threadpool/callable.go
Normal file
35
pkg/utils/threadpool/callable.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package threadpool
|
||||
|
||||
// Callable the tasks which returns the output after exit should implement this interface
|
||||
type Callable interface {
|
||||
Call() interface{}
|
||||
}
|
||||
|
||||
// Future is the handle returned after submitting a callable task to the thread threadpool
|
||||
type Future struct {
|
||||
response chan interface{}
|
||||
done bool
|
||||
}
|
||||
|
||||
// callableTask is internally used to wrap the callable and future together
|
||||
// So that the worker can send the response back through channel provided in Future object
|
||||
type callableTask struct {
|
||||
Task Callable
|
||||
Handle *Future
|
||||
}
|
||||
|
||||
// Get returns the response of the Callable task when done
|
||||
// Is is the blocking call it waits for the execution to complete
|
||||
func (f *Future) Get() interface{} {
|
||||
return <-f.response
|
||||
}
|
||||
|
||||
// IsDone returns true if the execution is already done
|
||||
func (f *Future) IsDone() bool {
|
||||
return f.done
|
||||
}
|
||||
|
||||
// Runnable is interface for the jobs that will be executed by the threadpool
|
||||
type Runnable interface {
|
||||
Run()
|
||||
}
|
||||
Reference in New Issue
Block a user