-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcallable.go
30 lines (25 loc) · 838 Bytes
/
callable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}