github.com/cilium/cilium@v1.16.2/pkg/bgpv1/agent/signaler/signaler.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  package signaler
     4  
     5  // BGPCPSignaler multiplexes multiple event sources into a single level-triggered
     6  // event instructing the BGP Control Plane Controller to perform reconciliation.
     7  //
     8  // BGPCPSignaler should always be constructed with a channel of size 1.
     9  //
    10  // Use of a BGPCPSignaler allows for bursts of events to be "rolled-up".
    11  // This is a suitable approach since the Controller checks the entire state of
    12  // the world on each iteration of its control loop.
    13  //
    14  // Additionally, this precludes any need for ordering between different event
    15  // sources.
    16  type BGPCPSignaler struct {
    17  	Sig chan struct{}
    18  }
    19  
    20  // NewSignaler constructs a Signaler
    21  func NewBGPCPSignaler() *BGPCPSignaler {
    22  	return &BGPCPSignaler{
    23  		Sig: make(chan struct{}, 1),
    24  	}
    25  }
    26  
    27  // Event adds an edge triggered event to the Signaler.
    28  //
    29  // A controller which uses this Signaler will be notified of this event some
    30  // time after.
    31  //
    32  // This signature adheres to the common event handling signatures of
    33  // cache.ResourceEventHandlerFuncs for convenience.
    34  func (s BGPCPSignaler) Event(_ interface{}) {
    35  	select {
    36  	case s.Sig <- struct{}{}:
    37  	default:
    38  	}
    39  }