Browse Source

built the WaitForStop functionality into the Stop method

pull/944/head
caffix 7 years ago
parent
commit
44f62e5e27
2 changed files with 7 additions and 11 deletions
  1. +7
    -9
      p2p/trust/metric.go
  2. +0
    -2
      p2p/trust/metric_test.go

+ 7
- 9
p2p/trust/metric.go View File

@ -165,8 +165,15 @@ func (tm *TrustMetric) Pause() {
}
// Stop tells the metric to stop recording data over time intervals
// This method also blocks until the metric has completely stopped
func (tm *TrustMetric) Stop() {
tm.stop <- struct{}{}
wait := make(chan struct{})
if tm.AddStopWaitChannel(wait) {
<-wait
}
}
// BadEvents indicates that an undesirable event(s) took place
@ -307,15 +314,6 @@ func (tm *TrustMetric) AddTimeIntervalWaitChannel(interval chan struct{}) bool {
return added
}
// WaitForStop blocks until the metric has completely stopped
func (tm *TrustMetric) WaitForStop() {
stop := make(chan struct{})
if tm.AddStopWaitChannel(stop) {
<-stop
}
}
// SignalStopped fires all the maintained signal channels and sets
// metric stopped status to true
func (tm *TrustMetric) SignalStopped() {


+ 0
- 2
p2p/trust/metric_test.go View File

@ -77,8 +77,6 @@ func TestTrustMetricStopPause(t *testing.T) {
tm.NextTimeInterval()
tm.NextTimeInterval()
tm.Stop()
// Wait for the stop to take place
tm.WaitForStop()
second := tm.Copy().numIntervals
// Allow more intervals to pass and check that the number of intervals match


Loading…
Cancel
Save