* * @returns {Promise }
()
| 152 | * @returns {Promise<boolean>} |
| 153 | */ |
| 154 | _ship() { |
| 155 | if (this._queue.length === 0) { |
| 156 | return Promise.resolve(false); |
| 157 | } |
| 158 | |
| 159 | let wait = this._activeShipper || Promise.resolve(false); |
| 160 | let shipper = this._activeShipper = wait |
| 161 | .then(() => { |
| 162 | let more = drained => { |
| 163 | if (drained) { |
| 164 | // If the queue was drained, let the timer |
| 165 | // push us forwards. |
| 166 | return true; |
| 167 | } |
| 168 | return this._sendBatch().then(d => more(d)); |
| 169 | } |
| 170 | return this._sendBatch().then(drained => more(drained)); |
| 171 | }) |
| 172 | .then(() => this._reset(shipper), e => { |
| 173 | this._onError(e); |
| 174 | this._reset(shipper); |
| 175 | }); |
| 176 | |
| 177 | return shipper; |
| 178 | } |
| 179 | |
| 180 | _sendBatch() { |
| 181 | if (this._queue.length === 0) { |
no test coverage detected