-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from shettyh/callable_impl
Callable implementation
- Loading branch information
Showing
6 changed files
with
108 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 pool | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters