MCPcopy Create free account
hub / github.com/assembla/cony / Loop

Method Loop

client.go:113–200  ·  view source on GitHub ↗

Loop should be run as condition for `for` with receiving from (*Client).Errors() It will manage AMQP connection, run queue and exchange declarations, consumers. Will start to return false once (*Client).Close() called.

()

Source from the content-addressed store, hash-verified

111// It will manage AMQP connection, run queue and exchange declarations, consumers.
112// Will start to return false once (*Client).Close() called.
113func (c *Client) Loop() bool {
114 var (
115 err error
116 )
117
118 if atomic.LoadInt32(&c.run) == noRun {
119 return false
120 }
121
122 conn, _ := c.conn.Load().(*amqp.Connection)
123
124 if conn != nil {
125 return true
126 }
127
128 if c.bo != nil {
129 time.Sleep(c.bo.Backoff(int(c.attempt)))
130 atomic.AddInt32(&c.attempt, 1)
131 }
132
133 // set default Heartbeat to 10 seconds like in original amqp.Dial
134 if c.config.Heartbeat == 0 {
135 c.config.Heartbeat = 10 * time.Second
136 }
137
138 conn, err = amqp.DialConfig(c.addr, c.config)
139
140 if c.reportErr(err) {
141 return true
142 }
143 c.conn.Store(conn)
144
145 atomic.StoreInt32(&c.attempt, 0)
146
147 // guard conn
148 go func() {
149 chanErr := make(chan *amqp.Error)
150 chanBlocking := make(chan amqp.Blocking)
151 conn.NotifyClose(chanErr)
152 conn.NotifyBlocked(chanBlocking)
153
154 // loop for blocking/deblocking
155 for {
156 select {
157 case err1 := <-chanErr:
158 c.reportErr(err1)
159
160 if conn1 := c.conn.Load().(*amqp.Connection); conn1 != nil {
161 c.conn.Store((*amqp.Connection)(nil))
162 conn1.Close()
163 }
164 // return from routine to launch reconnect process
165 return
166 case blocking := <-chanBlocking:
167 select {
168 case c.blocking <- blocking:
169 default:
170 }

Callers 9

ExampleFunction · 0.95
ExampleClient_LoopFunction · 0.95
TestClient_LoopFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 6

reportErrMethod · 0.95
channelMethod · 0.95
BackoffMethod · 0.65
NotifyCloseMethod · 0.65
CloseMethod · 0.65
serveMethod · 0.45

Tested by 3

ExampleFunction · 0.76
ExampleClient_LoopFunction · 0.76
TestClient_LoopFunction · 0.76