@Nullable IOException timeoutExit(@Nullable IOException cause) { if (!timeout.exit()) return cause; InterruptedIOException e = new InterruptedIOException("timeout"); if (cause != null) { e.initCause(cause); } return e; }
@Nullable IOException timeoutExit(@Nullable IOException cause) { if (!timeout.exit()) return cause; InterruptedIOException e = new InterruptedIOException("timeout"); if (cause != null) { e.initCause(cause); } return e; }
@Test public void singleInstanceTimedOut() throws Exception { a.enter(); Thread.sleep(500); assertTrue(a.exit()); assertTimedOut(a); }
@Test public void zeroTimeoutIsNoTimeout() throws Exception { AsyncTimeout timeout = new RecordingAsyncTimeout(); timeout.timeout(0, TimeUnit.MILLISECONDS); timeout.enter(); Thread.sleep(250); assertFalse(timeout.exit()); assertTimedOut(); }
@Nullable IOException timeoutExit(@Nullable IOException cause) { if (!timeout.exit()) return cause; InterruptedIOException e = new InterruptedIOException("timeout"); if (cause != null) { e.initCause(cause); } return e; }
/** * Throws an IOException if {@code throwOnTimeout} is {@code true} and a * timeout occurred. See {@link #newTimeoutException(IOException)} * for the type of exception thrown. */ final void exit(boolean throwOnTimeout) throws IOException { boolean timedOut = exit(); if (timedOut && throwOnTimeout) throw newTimeoutException(null); }
/** * Returns either {@code cause} or an IOException that's caused by * {@code cause} if a timeout occurred. See * {@link #newTimeoutException(IOException)} for the type of * exception returned. */ final IOException exit(IOException cause) throws IOException { if (!exit()) return cause; return newTimeoutException(cause); }