Skip to content

Commit b93561f

Browse files
committed
Make sure the quit signal is always handled by the upload workers
Closes #6
1 parent 6e5e4ce commit b93561f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/deployer.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,25 @@ func cleanup(paths []string, destBucket *s3.Bucket) error {
380380
// worker uploads files
381381
func (d *Deployer) worker(filesToUpload <-chan file, destBucket *s3.Bucket, errs chan<- error, quit chan struct{}) {
382382
defer d.wg.Done()
383-
for f := range filesToUpload {
383+
for {
384384
select {
385385
case <-quit:
386386
return
387-
default:
388-
}
389-
390-
err := d.upload(f, destBucket)
391-
if err != nil {
392-
fmt.Printf("Error uploading %s: %s\n", f.path, err)
393-
// if there are no errors on the channel, put this one there
394-
select {
395-
case errs <- err:
396-
default:
387+
case f, ok := <-filesToUpload:
388+
if !ok {
389+
return
390+
}
391+
err := d.upload(f, destBucket)
392+
if err != nil {
393+
fmt.Printf("Error uploading %s: %s\n", f.path, err)
394+
// if there are no errors on the channel, put this one there
395+
select {
396+
case errs <- err:
397+
default:
398+
}
397399
}
398400
}
399401
}
400-
401402
}
402403

403404
func (d *Deployer) upload(source file, destBucket *s3.Bucket) error {

0 commit comments

Comments
 (0)