public int waitForAsyncEvents()

in src/main/java/org/apache/sling/discovery/commons/providers/base/ViewStateManagerImpl.java [718:742]


    public int waitForAsyncEvents(long timeout) {
        long end = System.currentTimeMillis() + timeout;
        while(true) {
            int inFlightEventCnt = getInFlightAsyncEventCnt();
            if (inFlightEventCnt==0) {
                // no in-flight events - return 0
                return 0;
            }
            if (timeout==0) {
                // timeout is set to 'no-wait', but we have in-flight events,
                // return the actual cnt
                return inFlightEventCnt;
            }
            if (timeout<0 /*infinite waiting*/ || System.currentTimeMillis()<end) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    // ignore
                }
            } else {
                // timeout hit
                return inFlightEventCnt;
            }
        }
    }