MCPcopy Index your code
hub / github.com/TalkingData/owl / Get

Method Get

controller/queue.go:116–150  ·  view source on GitHub ↗

* If timeout less than 0, If Queue is empty, return (nil, ErrEmptyQueue). * If timeout equals to 0, block until get a value from Queue. * If timeout greater than 0, wait timeout seconds until get a value from Queue, if timeout passed, return (nil, ErrEmptyQueue).

(timeout float64)

Source from the content-addressed store, hash-verified

114// * If timeout greater than 0, wait timeout seconds until get a value from Queue,
115// if timeout passed, return (nil, ErrEmptyQueue).
116func (q *Queue) Get(timeout float64) (interface{}, error) {
117 q.mutex.Lock()
118 q.clearPending()
119 isempty := q.isempty()
120 if timeout < 0.0 && isempty {
121 q.mutex.Unlock()
122 return nil, ErrEmptyQueue
123 }
124
125 if !isempty {
126 v := q.get()
127 q.notifyPutter(nil)
128 q.mutex.Unlock()
129 return v, nil
130 }
131
132 e := q.newGetter()
133 q.mutex.Unlock()
134 w := e.Value.(waiter)
135
136 var v interface{}
137 if timeout == 0.0 {
138 v = <-w
139 } else {
140 select {
141 case v = <-w:
142 case <-time.After(time.Duration(timeout) * time.Second):
143 return nil, ErrEmptyQueue
144 }
145 }
146 q.mutex.Lock()
147 q.notifyPutter(e)
148 q.mutex.Unlock()
149 return v, nil
150}
151
152// Same as Put(-1).
153func (q *Queue) PutNoWait(val interface{}) error {

Callers 15

GetNoWaitMethod · 0.95
getHostByIDMethod · 0.45
getHostByHostnameMethod · 0.45
SendTSD2RepeaterMethod · 0.45
processResultMethod · 0.45
GetStrategyEventMethod · 0.45
GetScriptMethod · 0.45
GetOperationsCountMethod · 0.45
GetStrategiesCountMethod · 0.45
GetStrategyMethod · 0.45

Calls 5

clearPendingMethod · 0.95
isemptyMethod · 0.95
getMethod · 0.95
notifyPutterMethod · 0.95
newGetterMethod · 0.95

Tested by

no test coverage detected