vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vreplication/queryhistory/expectation_sequencer.go (about)

     1  package queryhistory
     2  
     3  // ExpectationSequencer is a convenient way to compose ExpectationSequences.
     4  type ExpectationSequencer interface {
     5  	ExpectationSequence
     6  	// Return the current SequencedExpectation.
     7  	Current() SequencedExpectation
     8  	// Eventually returns an ExpectationSequencerFn that can be used to compose
     9  	// this ExpectationSequencer with another.
    10  	//
    11  	// For example...
    12  	//	sequencer1.Then(sequencer2.Eventually())
    13  	//
    14  	// Produces an ExpectationSequence that starts with sequence1, and is
    15  	// eventually followed by the head of sequence2.
    16  	Eventually() ExpectationSequencerFn
    17  	// Immediately returns an ExpectationSequencerFn that can be used to
    18  	// compose this ExpectationSequencer with another.
    19  	//
    20  	// For example...
    21  	//	sequencer1.Then(sequencer2.Immediately())
    22  	//
    23  	// Produces an ExpectationSequence that starts with sequence1, and is
    24  	// immediately followed by the head of sequence2.
    25  	Immediately() ExpectationSequencerFn
    26  	// Then passes this ExpectationSequencer to ExpectationSequencerFn,
    27  	// and returns the resulting ExpectationSequencer.
    28  	Then(ExpectationSequencerFn) ExpectationSequencer
    29  }
    30  
    31  type ExpectationSequencerFn func(ExpectationSequencer) ExpectationSequencer
    32  
    33  type expectationSequencer struct {
    34  	ExpectationSequence
    35  	current SequencedExpectation
    36  }
    37  
    38  func (es *expectationSequencer) Current() SequencedExpectation {
    39  	return es.current
    40  }
    41  
    42  func (es *expectationSequencer) Eventually() ExpectationSequencerFn {
    43  	return func(parent ExpectationSequencer) ExpectationSequencer {
    44  		es.Current().ExpectEventuallyAfter(parent.Current())
    45  		return es
    46  	}
    47  }
    48  
    49  func (es *expectationSequencer) Immediately() ExpectationSequencerFn {
    50  	return func(parent ExpectationSequencer) ExpectationSequencer {
    51  		es.Current().ExpectImmediatelyAfter(parent.Current())
    52  		return es
    53  	}
    54  }
    55  
    56  func (es *expectationSequencer) Then(then ExpectationSequencerFn) ExpectationSequencer {
    57  	return then(es)
    58  }