How to use waitAsyncTasksFinished method of be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock.waitAsyncTasksFinished

Source:BukkitSchedulerMock.java Github

copy

Full Screen

...33 * Note that this function throws exception from old async tasks.34 */35 public void shutdown() throws RuntimeException36 {37 waitAsyncTasksFinished();38 pool.shutdown();39 40 if (asyncException.get() != null)41 throw new RuntimeException(asyncException.get());42 }43 44 /**45 * Get the current tick of the server.46 * @return The current tick of the server.47 */48 public long getCurrentTick()49 {50 return currentTick;51 }52 53 /**54 * Perform one tick on the server.55 */56 public void performOneTick()57 {58 currentTick++;59 List<ScheduledTask> oldTasks = tasks;60 tasks = new LinkedList<>();61 62 for (ScheduledTask task : oldTasks)63 {64 if (task.getScheduledTick() == currentTick && !task.isCancelled())65 {66 if (task.isSync())67 {68 task.run();69 }70 else71 {72 asyncTasksRunning.incrementAndGet();73 pool.execute(task.getRunnable());74 asyncTasksQueued--;75 }76 77 if (task instanceof RepeatingTask && !task.isCancelled())78 {79 ((RepeatingTask) task).updateScheduledTick();80 tasks.add(task);81 }82 }83 else if (!task.isCancelled())84 {85 tasks.add(task);86 }87 }88 }89 90 /**91 * Perform a number of ticks on the server.92 * @param ticks The number of ticks to executed.93 */94 public void performTicks(long ticks)95 {96 for (long i = 0; i < ticks; i++)97 {98 performOneTick();99 }100 }101 102 /**103 * Waits until all asynchronous tasks have finished executing.104 * If you have an asynchronous task that runs indefinitely,105 * this function will never return.106 */107 public void waitAsyncTasksFinished()108 {109 // Make sure all tasks (except for repeating async tasks, they only will fire once) get to execute.110 while (asyncTasksQueued > 0)111 performOneTick();112 113 // Wait for all tasks to finish executing.114 while (asyncTasksRunning.get() > 0)115 {116 try117 {118 Thread.sleep(1);119 }120 catch (InterruptedException e)121 {}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful