Executes all the callbacks in the current chain.
()
| 1229 | * Executes all the callbacks in the current chain. |
| 1230 | */ |
| 1231 | private void runCallbacks() { |
| 1232 | while (true) { |
| 1233 | Callback cb = null; |
| 1234 | Callback eb = null; |
| 1235 | synchronized (this) { |
| 1236 | // Read those into local variables so we can call doCall and invoke the |
| 1237 | // callbacks without holding the lock on `this', which would cause a |
| 1238 | // deadlock if we try to addCallbacks to `this' while a callback is |
| 1239 | // running. |
| 1240 | if (callbacks != null && next_callback != last_callback) { |
| 1241 | cb = callbacks[next_callback++]; |
| 1242 | eb = callbacks[next_callback++]; |
| 1243 | } |
| 1244 | // Also, we may need to atomically change the state to DONE. |
| 1245 | // Otherwise if another thread is blocked in addCallbacks right before |
| 1246 | // we're done processing the last element, we'd enter state DONE and |
| 1247 | // leave this method, and then addCallbacks would add callbacks that |
| 1248 | // would never get called. |
| 1249 | else { |
| 1250 | state = DONE; |
| 1251 | callbacks = null; |
| 1252 | next_callback = last_callback = 0; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | //final long start = System.nanoTime(); |
| 1258 | //LOG.debug("START >>>>>>>>>>>>>>>>>> doCall(" + cb + ", " + eb + ')'); |
| 1259 | if (doCall(result instanceof Exception ? eb : cb)) { |
| 1260 | //LOG.debug("PAUSE ================== doCall(" + cb + ", " + eb |
| 1261 | // + ") in " + (System.nanoTime() - start) / 1000 + "us"); |
| 1262 | break; |
| 1263 | } |
| 1264 | //LOG.debug("DONE <<<<<<<<<<<<<<<<<< doCall(" + cb + ", " + eb |
| 1265 | // + "), result=" + result |
| 1266 | // + " in " + (System.nanoTime() - start) / 1000 + "us"); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * Executes a single callback, handling continuation if it returns a Deferred. |
no test coverage detected