Add Submit() API for submitting async tasks. There are good reasons for asynchronous APIs to come back. #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I checked the issue and it seems that async APIs is provided in the early version but now have been deprecated. In this PR I want to resume the async APIs and give out my reason.
pool.Process()
is a sync API, and it will not return until the task is finished. Sometimes we need to submit async tasks. For running async tasks, one simple way is: (see issue #9)However, the above method cannot control the number growth of goroutines. If there are 4 workers but 10000 tasks, the above method will create 10000 goroutines. But we wish these are only 4 worker goroutines running these tasks. In this case,
pool.Submit()
is a better choice:The source code of tunny is short and elegant, but I think async APIs are necessary for a Go task pool module. Similar effects can be achieved by some indirect methods, but tunny has already provided the framework to do this in a more efficient way. So I actually only add a new API and a new Worker implementation for it, without changing the current APIs.