@Override public Runnable apply(Runnable t) throws Exception { Runnable[] ref = { t }; forEach(ref, this); return ref[0]; }
@Test public void normal() { manager.enable(); try { Disposable d1 = manager.register(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { manager.register(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { manager.disable(); manager.forEach(new Consumer<Function<Runnable, Runnable>>() { @Override public void accept(Function<Runnable, Runnable> f) manager.clear(); manager.forEach(new Consumer<Function<Runnable, Runnable>>() { @Override public void accept(Function<Runnable, Runnable> f)
@Test public void handlerCrash() throws Exception { manager.register(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { manager.register(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { manager.apply(Functions.EMPTY_RUNNABLE); manager.forEach(new Consumer<Function<Runnable, Runnable>>() { @Override public void accept(Function<Runnable, Runnable> f)
@Test public void append() { try { manager.append(); manager.disable(); manager.enable(); manager.append(); manager.disable(); assertNull(RxJavaPlugins.getScheduleHandler()); RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { calls++; return r; } }); manager.append(); manager.register(new Function<Runnable, Runnable>() { @Override public Runnable apply(Runnable r) throws Exception { calls++; return r; } }); RxJavaPlugins.onSchedule(Functions.EMPTY_RUNNABLE); assertEquals(2, calls); } finally { RxJavaPlugins.reset(); } }
@Test public void forEachConsumerRace() { for (int i = 0; i < 1000; i++) { final Disposable d = manager.register(Functions.<Runnable>identity()); assertTrue(manager.hasHandlers()); Runnable r1 = new Runnable() { @Override public void run() { d.dispose(); } }; Runnable r2 = new Runnable() { @Override public void run() { manager.forEach(Functions.<Function<Runnable, Runnable>>emptyConsumer()); } }; TestHelper.race(r1, r2, Schedulers.single()); assertFalse(manager.hasHandlers()); } }
/** * Adds the current non-null OnSchedule hook to this handler and replaces it * in RxJavaPlugins with this OnScheduleMultiHandlerManager. */ public void append() { @SuppressWarnings("unchecked") Function<Runnable, Runnable> existing = (Function<Runnable, Runnable>)RxJavaPlugins.getScheduleHandler(); if (existing != this) { if (existing != null) { register(existing); } RxJavaPlugins.setScheduleHandler(this); } }
@Test public void forEachBiConsumerRace() { for (int i = 0; i < 1000; i++) { final Disposable d = manager.register(Functions.<Runnable>identity()); assertTrue(manager.hasHandlers()); assertFalse(manager.hasHandlers());
/** * Adds the current non-null OnSchedule hook to this handler and replaces it * in RxJavaPlugins with this OnScheduleMultiHandlerManager. */ public void append() { @SuppressWarnings("unchecked") Function<Runnable, Runnable> existing = (Function<Runnable, Runnable>)RxJavaPlugins.getScheduleHandler(); if (existing != this) { if (existing != null) { register(existing); } RxJavaPlugins.setScheduleHandler(this); } }
@Override public Runnable apply(Runnable t) throws Exception { Runnable[] ref = { t }; forEach(ref, this); return ref[0]; }
@Override public void run() { manager.forEach(0, new BiConsumer<Integer, Function<Runnable, Runnable>>() { @Override public void accept(Integer s, Function<Runnable, Runnable> f) throws Exception { // no op } }); } };
@Override public void run() { manager.forEach(Functions.<Function<Runnable, Runnable>>emptyConsumer()); } };