github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/s3caller/worker.go (about)

     1  // Copyright 2023 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package s3caller
     5  
     6  import (
     7  	"github.com/juju/worker/v3"
     8  	"gopkg.in/tomb.v2"
     9  
    10  	"github.com/juju/juju/internal/s3client"
    11  )
    12  
    13  // logger is here to stop the desire of creating a package level logger.
    14  // Don't do this, instead use the one passed as manifold config.
    15  type logger interface{}
    16  
    17  var _ logger = struct{}{}
    18  
    19  func newS3ClientWorker(session s3client.Session) worker.Worker {
    20  	w := &s3ClientWorker{session: session}
    21  	w.tomb.Go(w.loop)
    22  	return w
    23  }
    24  
    25  type s3ClientWorker struct {
    26  	tomb    tomb.Tomb
    27  	session s3client.Session
    28  }
    29  
    30  // Kill is part of the worker.Worker interface.
    31  func (w *s3ClientWorker) Kill() {
    32  	w.tomb.Kill(nil)
    33  }
    34  
    35  // Wait is part of the worker.Worker interface.
    36  func (w *s3ClientWorker) Wait() error {
    37  	return w.tomb.Wait()
    38  }
    39  
    40  func (w *s3ClientWorker) loop() (err error) {
    41  	for {
    42  		select {
    43  		case <-w.tomb.Dying():
    44  			return tomb.ErrDying
    45  		}
    46  	}
    47  }