MCPcopy
hub / github.com/uber-go/zap / Stop

Method Stop

zapcore/buffered_write_syncer.go:190–220  ·  view source on GitHub ↗

Stop closes the buffer, cleans up background goroutines, and flushes remaining unwritten data.

()

Source from the content-addressed store, hash-verified

188// Stop closes the buffer, cleans up background goroutines, and flushes
189// remaining unwritten data.
190func (s *BufferedWriteSyncer) Stop() (err error) {
191 // Critical section.
192 stopped := func() bool {
193 s.mu.Lock()
194 defer s.mu.Unlock()
195
196 if !s.initialized {
197 return false
198 }
199
200 if s.stopped {
201 return false
202 }
203 s.stopped = true
204
205 s.ticker.Stop()
206 close(s.stop) // tell flushLoop to stop
207 return true
208 }()
209
210 // Not initialized, or already stopped, no need for any cleanup.
211 if !stopped {
212 return
213 }
214
215 // Wait for flushLoop to end outside of the lock, as it may need the lock to complete.
216 // See https://github.com/uber-go/zap/issues/1428 for details.
217 <-s.done
218
219 return s.Sync()
220}

Callers 7

TestBufferWriterFunction · 0.95
TestSamplerConcurrentFunction · 0.80
TestMockClock_NewTickerFunction · 0.80

Calls 1

SyncMethod · 0.95

Tested by 7

TestBufferWriterFunction · 0.76
TestSamplerConcurrentFunction · 0.64
TestMockClock_NewTickerFunction · 0.64