@Test public void schedule() { FakeClock clock = new FakeClock(); ScheduledHandle handle = syncContext.schedule(task1, 110, TimeUnit.NANOSECONDS, clock.getScheduledExecutorService()); assertThat(handle.isPending()).isTrue(); assertThat(clock.runDueTasks()).isEqualTo(0); assertThat(clock.forwardNanos(109)).isEqualTo(0); assertThat(handle.isPending()).isTrue(); verify(task1, never()).run(); assertThat(clock.forwardNanos(1)).isEqualTo(1); assertThat(handle.isPending()).isFalse(); verify(task1).run(); }
public final ScheduledHandle schedule( final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService) { final ManagedRunnable runnable = new ManagedRunnable(task); ScheduledFuture<?> future = timerService.schedule(new Runnable() { @Override public void run() { execute(runnable); } @Override public String toString() { return task.toString() + "(scheduled in SynchronizationContext)"; } }, delay, unit); return new ScheduledHandle(runnable, future); }
SynchronizationContext implements Executor { public final ScheduledHandle schedule( final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService) { final ManagedRunnable runnable = new ManagedRunnable(task); ScheduledFuture<?> future = timerService.schedule(new Runnable() { @Override public void run() { execute(runnable); } @Override public String toString() { return task.toString() + "(scheduled in SynchronizationContext)"; } }, delay, unit); return new ScheduledHandle(runnable, future); } }
SynchronizationContext implements Executor { public final ScheduledHandle schedule( final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService) { final ManagedRunnable runnable = new ManagedRunnable(task); ScheduledFuture<?> future = timerService.schedule(new Runnable() { @Override public void run() { execute(runnable); } @Override public String toString() { return task.toString() + "(scheduled in SynchronizationContext)"; } }, delay, unit); return new ScheduledHandle(runnable, future); } SynchronizationContext(UncaughtExceptionHandler uncaughtExceptionHandler); }
SynchronizationContext implements Executor { public final ScheduledHandle schedule( final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService) { final ManagedRunnable runnable = new ManagedRunnable(task); ScheduledFuture<?> future = timerService.schedule(new Runnable() { @Override public void run() { execute(runnable); } @Override public String toString() { return task.toString() + "(scheduled in SynchronizationContext)"; } }, delay, unit); return new ScheduledHandle(runnable, future); } SynchronizationContext(UncaughtExceptionHandler uncaughtExceptionHandler); final void drain(); final void executeLater(Runnable runnable); @Override final void execute(Runnable task); void throwIfNotInThisSynchronizationContext(); final ScheduledHandle schedule(
      final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService); }
SynchronizationContext implements Executor { public final ScheduledHandle schedule( final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService) { final ManagedRunnable runnable = new ManagedRunnable(task); ScheduledFuture<?> future = timerService.schedule(new Runnable() { @Override public void run() { execute(runnable); } @Override public String toString() { return task.toString() + "(scheduled in SynchronizationContext)"; } }, delay, unit); return new ScheduledHandle(runnable, future); } SynchronizationContext(UncaughtExceptionHandler uncaughtExceptionHandler); final void drain(); final void executeLater(Runnable runnable); @Override final void execute(Runnable task); void throwIfNotInThisSynchronizationContext(); final ScheduledHandle schedule(
      final Runnable task, long delay, TimeUnit unit, ScheduledExecutorService timerService);  }