refactor(worker): use write blocking for semaphore

This commit is contained in:
bigeagle 2016-04-24 17:02:49 +08:00
parent 6b05a5894e
commit 26b7ef9a9c
No known key found for this signature in database
GPG Key ID: 9171A4571C27920A
2 changed files with 2 additions and 4 deletions

View File

@ -138,8 +138,8 @@ func runMirrorJob(provider mirrorProvider, ctrlChan <-chan ctrlAction, managerCh
runJob := func(kill <-chan empty, jobDone chan<- empty) {
select {
case <-semaphore:
defer func() { semaphore <- empty{} }()
case semaphore <- empty{}:
defer func() { <-semaphore }()
runJobWrapper(kill, jobDone)
case <-kill:
jobDone <- empty{}

View File

@ -66,7 +66,6 @@ func TestMirrorJob(t *testing.T) {
ctrlChan := make(chan ctrlAction)
managerChan := make(chan struct{})
semaphore := make(chan empty, 1)
semaphore <- empty{}
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
for i := 0; i < 2; i++ {
@ -105,7 +104,6 @@ echo $TUNASYNC_WORKING_DIR
ctrlChan := make(chan ctrlAction)
managerChan := make(chan struct{})
semaphore := make(chan empty, 1)
semaphore <- empty{}
Convey("If we kill it", func(ctx C) {
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)