Async version of {@link #exceptionMiddleware()}
507884
static <T> Middleware<SyncHandler<Response<T>>, AsyncHandler<Response<T>>> exceptionHandler() {
    return CalculatorApp.<T>exceptionMiddleware().and(Middleware::syncToAsync);
  }
245757
void handle(OngoingRequest ongoingRequest, RequestContext requestContext, Endpoint endpoint) {
    try {
      endpoint.invoke(requestContext)
          .whenComplete((message, throwable) -> {
            try {
              if (message != null) {
                ongoingRequest.reply(message);
              } else if (throwable != null) {
                // unwrap CompletionException
                if (throwable instanceof CompletionException) {
                  throwable = throwable.getCause();
                }
                handleException(throwable, ongoingRequest);
              } else {
                LOG.error(
                    "Both message and throwable null in EndpointInvocationHandler for request "
                    + ongoingRequest
                    + " - this shouldn't happen!");
                handleException(new IllegalStateException("Both message and throwable null"),
                                ongoingRequest);
              }
            } catch (Throwable t) {
              // don't try to respond here; just log the fact that responding failed.
              LOG.error("Exception caught when replying", t);
            }
          });
    } catch (Exception e) {
      handleException(e, ongoingRequest);
    }
  }
1226344
public synchronized boolean waitForFinish() throws Throwable {
    while (!done && exception == null) {
      wait();
    }
    if (exception != null) {
      throw exception;
    }
    return done;
  }
177168
public synchronized final void start()
    	throws Exception
    {
        if (_started || _starting)
            return;
        
        _starting=true;
        
        if (log.isDebugEnabled()) log.debug("Starting "+this);
        LifeCycleEvent event = new LifeCycleEvent(this);
        for(int i=0;i<LazyList.size(_eventListeners);i++)
        {
            EventListener listener=(EventListener)LazyList.get(_eventListeners,i);
            if (listener instanceof LifeCycleListener)
                ((LifeCycleListener)listener).lifeCycleStarting(event);
        }
        
        try
        {
            doStart();
            _started=true;
            log.info("Started "+this);
            for(int i=0;i<LazyList.size(_eventListeners);i++)
            {
                EventListener listener=(EventListener)LazyList.get(_eventListeners,i);
                if (listener instanceof LifeCycleListener)
                    ((LifeCycleListener)listener).lifeCycleStarted(event);
            }
        }
        catch(Throwable e)
        {
            LifeCycleEvent failed = new LifeCycleEvent(this,e);
            for(int i=0;i<LazyList.size(_eventListeners);i++)
            {
                EventListener listener=(EventListener)LazyList.get(_eventListeners,i);
                if (listener instanceof LifeCycleListener)
                    ((LifeCycleListener)listener).lifeCycleFailure(event);
            }
            if (e instanceof Exception)
                throw (Exception)e;
            if (e instanceof RuntimeException)
                throw (RuntimeException)e;
            if (e instanceof Error)
                throw (Error)e;
            log.warn(LogSupport.EXCEPTION, e);
        }
        finally
        {
            _starting=false;
        }
    }
164319
private void processUncaughtException(Thread thread, Throwable throwable) {
        if (exceptionPurger != null) {
            throwable = exceptionPurger.purge(throwable);
        }
        logException(thread, throwable);
        notifyUserAboutException(thread, throwable);
    }
23476
public Sink reloadAsync() throws ExecutionException, InterruptedException {
    // [START reloadAsync]
    Future<Sink> future = sink.reloadAsync();
    // ...
    Sink latestSink = future.get();
    if (latestSink == null) {
      // the sink was not found
    }
    // [END reloadAsync]
    return latestSink;
  }
859523
@Override
	public ISynchronizationPoint<Exception> start() {
		SynchronizationPoint<Exception> sp = new SynchronizationPoint<>();
		io.canStartReading().listenAsync(new Task.Cpu.FromRunnable(() -> {
			try {
				Starter start = new Starter(io, defaultEncoding, charactersBuffersSize, maxBuffers);
				stream = start.start();
				next().listenInline(sp);
			} catch (Exception e) {
				sp.error(e);
			}
		}, "Start parsing XML", io.getPriority()), true);
		return sp;
	}
595245
public static void asyncExecute(Runnable runnable) {
		if (runnable != null) {
			try {
				Para.getExecutorService().execute(runnable);
			} catch (RejectedExecutionException ex) {
				logger.warn(ex.getMessage());
				try {
					runnable.run();
				} catch (Exception e) {
					logger.error(null, e);
				}
			}
		}
	}
1140215
private static <E extends RuntimeException> E handleException(E ex) {
        if (JodaTime.hasExpectedBehavior())
            return ex;
        throw new IllegalStateException("Joda-time 2.2 or later version is required, but found version: " + JodaTime.getVersion(), ex);
    }
145859
public void waitUntilFinish() {
        while (!finished) {
            synchronized (waitingLock) {
                if (config.isHaltOnError()) {
                    Throwable t = getError();
                    if (t != null && config.isHaltOnError()) {
                        if (t instanceof RuntimeException) {
                            throw (RuntimeException)t;
                        } else if (t instanceof Error) {
                            throw (Error)t;
                        } else {
                            throw new RuntimeException("error on monitor thread", t);
                        }
                    }
                }
                if (finished) {
                    return;
                }
                try {
                    waitingLock.wait();
                } catch (InterruptedException e) {
                    logger.error("Error occurred", e);
                }
            }
        }
    }
395211
def AsyncResponseMiddleware(environ, resp):
    '''
    '''
    future = create_future()
    future._loop.call_soon(future.set_result, resp)
    return future
753946
public void waitUntilNoMoreException(final Runnable runnable, final List<Class<? extends Exception>> expectedExceptions) {

        final List<RuntimeException> actualExceptions = new ArrayList<>();
        int tries = 0;
        while (tries < maxTries) {
            try {
                runnable.run();
                return;
            } catch (final RuntimeException ex) {
                if (!Utils4J.expectedException(ex, expectedExceptions) && !Utils4J.expectedCause(ex, expectedExceptions)) {
                    throw ex;
                }
                actualExceptions.add(ex);
                tries++;
                Utils4J.sleep(sleepMillis);
            }
        }
        throw new IllegalStateException("Waited too long for execution without exception. Expected exceptions: " + expectedExceptions
                + ", Actual exceptions: " + actualExceptions);

    }
420176
public void process(final boolean asynch)
          throws NotificationException {
    if (asynch) {
      try {
        consumer.setMessageListener(this);
        return;
      } catch (final JMSException je) {
        throw new NotificationException(je);
      }
    }

    while (running) {
      final Message m = conn.receive();

      if (m == null) {
        running = false;
        return;
      }
      onMessage(m);
    }
  }
1093842
public Object proceed() throws Throwable, Exception {
		if (currentInterceptorInt == interceptors.size() - 1) {
			Debug.logVerbose("[JdonFramework] finish call all inteceptors", module);
			return beforeAfterMethodTarget.invoke(method, args, methodProxy);
		}

		Object interceptor = interceptors.get(++currentInterceptorInt);
		if (interceptor != null) {
			MethodInterceptor methodInterceptor = (MethodInterceptor) interceptor;
			return methodInterceptor.invoke(this);
		} else {
			Debug.logVerbose("[JdonFramework] null finish call all inteceptors", module);
			return beforeAfterMethodTarget.invoke(method, args, methodProxy);
		}
	}
739490
private int externalInterruptibleAwaitDone() throws InterruptedException {
    int s;
    if (Thread.interrupted())
      throw new InterruptedException();
    if ((s = status) >= 0 && (s = ((this instanceof CountedCompleter)
        ? ForkJoinPool.common.externalHelpComplete((CountedCompleter<?>) this, 0)
        : ForkJoinPool.common.tryExternalUnpush(this) ? doExec() : 0)) >= 0) {
      while ((s = status) >= 0) {
        if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
          synchronized (this) {
            if (status >= 0)
              wait(0L);
            else
              notifyAll();
          }
        }
      }
    }
    return s;
  }
688416
public T get() throws Exception {
    waitForPromiseSuccess();

    if (response != null) {
      return response;
    } else {
      if (this.exception instanceof IOException) {
        throw (IOException) this.exception;
      } else if (this.exception instanceof io.netty.handler.timeout.TimeoutException) {
        throw new TimeoutException();
      } else {
        throw new IOException(this.exception);
      }
    }
  }
113354
public IllegalStateException asJDKException() {
        IllegalStateException e = new IllegalStateException(getMessage()) {
            @Override
            public synchronized Throwable fillInStackTrace() {
                return this;
            }
        };
        e.setStackTrace(getStackTrace());
        return e;
    }