/** * Checks if the {@code failOnNonBlockingScheduler} plugin setting is enabled and the current * thread is a Scheduler sensitive to blocking operators. * @throws IllegalStateException if the {@code failOnNonBlockingScheduler} and the current thread is sensitive to blocking */ public static void verifyNonBlocking() { if (RxJavaCommonPlugins.isFailOnNonBlockingScheduler() && (Thread.currentThread() instanceof NonBlockingThread || RxJavaCommonPlugins.onBeforeBlocking())) { throw new IllegalStateException("Attempt to block on a Scheduler " + Thread.currentThread().getName() + " that doesn't support blocking operators as they may lead to deadlock"); } } }
/** * Checks if the {@code failOnNonBlockingScheduler} plugin setting is enabled and the current * thread is a Scheduler sensitive to blocking operators. * @throws IllegalStateException if the {@code failOnNonBlockingScheduler} and the current thread is sensitive to blocking */ public static void verifyNonBlocking() { if (RxJavaCommonPlugins.isFailOnNonBlockingScheduler() && (Thread.currentThread() instanceof NonBlockingThread || RxJavaCommonPlugins.onBeforeBlocking())) { throw new IllegalStateException("Attempt to block on a Scheduler " + Thread.currentThread().getName() + " that doesn't support blocking operators as they may lead to deadlock"); } } }
/** * Checks if the {@code failOnNonBlockingScheduler} plugin setting is enabled and the current * thread is a Scheduler sensitive to blocking operators. * @throws IllegalStateException if the {@code failOnNonBlockingScheduler} and the current thread is sensitive to blocking */ public static void verifyNonBlocking() { if (RxJavaCommonPlugins.isFailOnNonBlockingScheduler() && (Thread.currentThread() instanceof NonBlockingThread || RxJavaCommonPlugins.onBeforeBlocking())) { throw new IllegalStateException("Attempt to block on a Scheduler " + Thread.currentThread().getName() + " that doesn't support blocking operators as they may lead to deadlock"); } } }
@Test public void onBeforeBlocking() { try { RxJavaCommonPlugins.setOnBeforeBlocking(new BooleanSupplier() { @Override public boolean getAsBoolean() throws Exception { throw new IllegalArgumentException(); } }); try { RxJavaCommonPlugins.onBeforeBlocking(); fail("Should have thrown"); } catch (IllegalArgumentException ex) { // expected } } finally { RxJavaCommonPlugins.reset(); } }