mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-21 04:42:46 +00:00
refactor(worker): use write blocking for semaphore
This commit is contained in:
parent
6b05a5894e
commit
26b7ef9a9c
@ -138,8 +138,8 @@ func runMirrorJob(provider mirrorProvider, ctrlChan <-chan ctrlAction, managerCh
|
|||||||
|
|
||||||
runJob := func(kill <-chan empty, jobDone chan<- empty) {
|
runJob := func(kill <-chan empty, jobDone chan<- empty) {
|
||||||
select {
|
select {
|
||||||
case <-semaphore:
|
case semaphore <- empty{}:
|
||||||
defer func() { semaphore <- empty{} }()
|
defer func() { <-semaphore }()
|
||||||
runJobWrapper(kill, jobDone)
|
runJobWrapper(kill, jobDone)
|
||||||
case <-kill:
|
case <-kill:
|
||||||
jobDone <- empty{}
|
jobDone <- empty{}
|
||||||
|
@ -66,7 +66,6 @@ func TestMirrorJob(t *testing.T) {
|
|||||||
ctrlChan := make(chan ctrlAction)
|
ctrlChan := make(chan ctrlAction)
|
||||||
managerChan := make(chan struct{})
|
managerChan := make(chan struct{})
|
||||||
semaphore := make(chan empty, 1)
|
semaphore := make(chan empty, 1)
|
||||||
semaphore <- empty{}
|
|
||||||
|
|
||||||
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
|
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
@ -105,7 +104,6 @@ echo $TUNASYNC_WORKING_DIR
|
|||||||
ctrlChan := make(chan ctrlAction)
|
ctrlChan := make(chan ctrlAction)
|
||||||
managerChan := make(chan struct{})
|
managerChan := make(chan struct{})
|
||||||
semaphore := make(chan empty, 1)
|
semaphore := make(chan empty, 1)
|
||||||
semaphore <- empty{}
|
|
||||||
|
|
||||||
Convey("If we kill it", func(ctx C) {
|
Convey("If we kill it", func(ctx C) {
|
||||||
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
|
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user