MCPcopy
hub / github.com/nats-io/nats.go / FlushTimeout

Method FlushTimeout

nats.go:5798–5836  ·  view source on GitHub ↗

FlushTimeout allows a Flush operation to have an associated timeout.

(timeout time.Duration)

Source from the content-addressed store, hash-verified

5796
5797// FlushTimeout allows a Flush operation to have an associated timeout.
5798func (nc *Conn) FlushTimeout(timeout time.Duration) (err error) {
5799 if nc == nil {
5800 return ErrInvalidConnection
5801 }
5802 if timeout <= 0 {
5803 return ErrBadTimeout
5804 }
5805
5806 nc.mu.Lock()
5807 if nc.isClosed() {
5808 nc.mu.Unlock()
5809 return ErrConnectionClosed
5810 }
5811 t := globalTimerPool.Get(timeout)
5812 defer globalTimerPool.Put(t)
5813
5814 // Create a buffered channel to prevent chan send to block
5815 // in processPong() if this code here times out just when
5816 // PONG was received.
5817 ch := make(chan struct{}, 1)
5818 nc.sendPing(ch)
5819 nc.mu.Unlock()
5820
5821 select {
5822 case _, ok := <-ch:
5823 if !ok {
5824 err = ErrConnectionClosed
5825 } else {
5826 close(ch)
5827 }
5828 case <-t.C:
5829 err = ErrTimeout
5830 }
5831
5832 if err != nil {
5833 nc.removeFlushEntry(ch)
5834 }
5835 return
5836}
5837
5838// RTT calculates the round trip time between this client and the server.
5839func (nc *Conn) RTT() (time.Duration, error) {

Callers 12

RTTMethod · 0.95
FlushMethod · 0.95
drainConnectionMethod · 0.95
TestNilConnectionFunction · 0.95
ExampleConn_FlushTimeoutFunction · 0.45
TestFlushReleaseOnCloseFunction · 0.45
TestNkeyAuthFunction · 0.45
TestSlowSubscriberFunction · 0.45
TestSlowChanSubscriberFunction · 0.45
TestSlowAsyncSubscriberFunction · 0.45
TestFlushFunction · 0.45

Calls 5

isClosedMethod · 0.95
sendPingMethod · 0.95
removeFlushEntryMethod · 0.95
GetMethod · 0.65
PutMethod · 0.65

Tested by 9

TestNilConnectionFunction · 0.76
ExampleConn_FlushTimeoutFunction · 0.36
TestFlushReleaseOnCloseFunction · 0.36
TestNkeyAuthFunction · 0.36
TestSlowSubscriberFunction · 0.36
TestSlowChanSubscriberFunction · 0.36
TestSlowAsyncSubscriberFunction · 0.36
TestFlushFunction · 0.36