Skip to content

Conversation

@daniel-hutao
Copy link
Contributor

  • Modified the executeTaskWithTimeout function in worker.go to stop the task when the context is cancelled.
  • Updated the Wait function in gopool.go to wait until all tasks are completed, not just dispatched.
  • Added a new test case TestGoPoolWithTimeout in gopool_test.go to test the behavior of goPool when a task times out.
  • Used the existing lock field in goPool to protect concurrent access to workerStack in Wait and popWorker functions.

fix #6

- Modified the `executeTaskWithTimeout` function in `worker.go` to stop the task when the context is cancelled.
- Updated the `Wait` function in `gopool.go` to wait until all tasks are completed, not just dispatched.
- Added a new test case `TestGoPoolWithTimeout` in `gopool_test.go` to test the behavior of goPool when a task times out.
- Used the existing `lock` field in `goPool` to protect concurrent access to `workerStack` in `Wait` and `popWorker` functions.

Signed-off-by: Daniel Hu <tao.hu@merico.dev>
@daniel-hutao daniel-hutao merged commit 6fbdbde into main Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestGoPoolWithMutex 测试用例添加 WithTimeout 无法通过 race 测试

1 participant