...

Source file src/github.com/launchdarkly/go-server-sdk/v6/internal/bigsegments/big_segment_store_status_provider_impl.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/internal/bigsegments

     1  package bigsegments
     2  
     3  import (
     4  	"github.com/launchdarkly/go-server-sdk/v6/interfaces"
     5  	"github.com/launchdarkly/go-server-sdk/v6/internal"
     6  )
     7  
     8  // This is the standard implementation of BigSegmentStoreStatusProvider. Most of the work is done by
     9  // BigSegmentStoreManager, which exposes the methods that other SDK components need to access the store.
    10  //
    11  // We always create this component regardless of whether there really is a store. If there is no store (so
    12  // there is no BigSegmentStoreManager) then we won't actually be doing any Big Segments stuff, or sending
    13  // any status updates, but this API object still exists so your app won't crash if you try to use
    14  // GetStatus or AddStatusListener.
    15  type bigSegmentStoreStatusProviderImpl struct {
    16  	getStatusFn func() interfaces.BigSegmentStoreStatus
    17  	broadcaster *internal.Broadcaster[interfaces.BigSegmentStoreStatus]
    18  }
    19  
    20  // NewBigSegmentStoreStatusProviderImpl creates the internal implementation of
    21  // BigSegmentStoreStatusProvider. The manager parameter can be nil if there is no Big Segment store.
    22  func NewBigSegmentStoreStatusProviderImpl(
    23  	getStatusFn func() interfaces.BigSegmentStoreStatus,
    24  	broadcaster *internal.Broadcaster[interfaces.BigSegmentStoreStatus],
    25  ) interfaces.BigSegmentStoreStatusProvider {
    26  	return &bigSegmentStoreStatusProviderImpl{
    27  		getStatusFn: getStatusFn,
    28  		broadcaster: broadcaster,
    29  	}
    30  }
    31  
    32  func (b *bigSegmentStoreStatusProviderImpl) GetStatus() interfaces.BigSegmentStoreStatus {
    33  	if b.getStatusFn == nil {
    34  		return interfaces.BigSegmentStoreStatus{Available: false}
    35  	}
    36  	return b.getStatusFn()
    37  }
    38  
    39  func (b *bigSegmentStoreStatusProviderImpl) AddStatusListener() <-chan interfaces.BigSegmentStoreStatus {
    40  	return b.broadcaster.AddListener()
    41  }
    42  
    43  func (b *bigSegmentStoreStatusProviderImpl) RemoveStatusListener(
    44  	ch <-chan interfaces.BigSegmentStoreStatus,
    45  ) {
    46  	b.broadcaster.RemoveListener(ch)
    47  }
    48  

View as plain text