Skip to content

Commit

Permalink
Merge pull request #86 from seeseemelk/bugfix/zero-delay-timer
Browse files Browse the repository at this point in the history
Fix zero delay timers not being run
  • Loading branch information
seeseemelk committed Jun 30, 2020
2 parents 5c06c12 + 7b52212 commit c90cede
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public BukkitTask runTask(Plugin plugin, BukkitRunnable task)
@Override
public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay)
{
delay = Math.max(delay, 1);
ScheduledTask scheduledTask = new ScheduledTask(id++, plugin, true, currentTick + delay, task);
tasks.add(scheduledTask);
return scheduledTask;
Expand All @@ -151,6 +152,7 @@ public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay)
@Override
public BukkitTask runTaskTimer(Plugin plugin, Runnable task, long delay, long period)
{
delay = Math.max(delay, 1);
RepeatingTask repeatingTask = new RepeatingTask(id++, plugin, true, currentTick + delay, period, task);
tasks.add(repeatingTask);
return repeatingTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public void runTaskTimer_SelfCancelling()
assertEquals(2, count.get());
}

@Test
public void runTaskTimer_ZeroDelay_DoesntExecuteTaskImmediately()
{
AtomicInteger count = new AtomicInteger(0);
Runnable callback = () -> count.incrementAndGet();
scheduler.runTaskTimer(null, callback, 0, 2L);
assertEquals(0, count.get());
scheduler.performTicks(1L);
assertEquals(1, count.get());
}

@Test
public void runTaskAsynchronously_TaskExecutedOnSeperateThread() throws InterruptedException, BrokenBarrierException, TimeoutException
{
Expand Down

0 comments on commit c90cede

Please sign in to comment.