github.com/safing/portbase@v0.19.5/updater/notifier.go (about)

     1  package updater
     2  
     3  import (
     4  	"github.com/tevino/abool"
     5  )
     6  
     7  type notifier struct {
     8  	upgradeAvailable *abool.AtomicBool
     9  	notifyChannel    chan struct{}
    10  }
    11  
    12  func newNotifier() *notifier {
    13  	return &notifier{
    14  		upgradeAvailable: abool.NewBool(false),
    15  		notifyChannel:    make(chan struct{}),
    16  	}
    17  }
    18  
    19  func (n *notifier) markAsUpgradeable() {
    20  	if n.upgradeAvailable.SetToIf(false, true) {
    21  		close(n.notifyChannel)
    22  	}
    23  }
    24  
    25  // UpgradeAvailable returns whether an upgrade is available for this file.
    26  func (file *File) UpgradeAvailable() bool {
    27  	return file.notifier.upgradeAvailable.IsSet()
    28  }
    29  
    30  // WaitForAvailableUpgrade blocks (selectable) until an upgrade for this file is available.
    31  func (file *File) WaitForAvailableUpgrade() <-chan struct{} {
    32  	return file.notifier.notifyChannel
    33  }