Skip to content

Commit

Permalink
Fix Issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
letsfire committed Nov 18, 2019
1 parent f1e722c commit 5b15285
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion issue/0001_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ func TestNewMaster(t *testing.T) {
fmt.Println(master.Running()) // 正在运行的协程工人数量

fmt.Println(runtime.NumGoroutine()) // 通常会大于 2
time.Sleep(time.Nanosecond) // 极短暂休眠
time.Sleep(time.Millisecond * 5) // 极短暂休眠
fmt.Println(runtime.NumGoroutine()) // 必须会等于 2
}
3 changes: 2 additions & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package factory
import (
"fmt"
"sync/atomic"
"time"
)

type exitSignal struct{}
Expand Down Expand Up @@ -60,7 +61,7 @@ func newWorker() (w *worker) {
select {
case params := <-w.params:
w.action(params)
default:
case <-time.Tick(time.Millisecond):
}
// 关闭任务通道
close(w.params)
Expand Down

0 comments on commit 5b15285

Please sign in to comment.