Amend LibAC's delayed execution service to have a internal start and stop API

This commit is contained in:
Aria 2023-04-20 19:00:54 -07:00
parent bbafb83966
commit 2e734773a0
2 changed files with 30 additions and 4 deletions

View file

@ -12,9 +12,9 @@ plugins {
id 'maven-publish'
}
version = "1.0.1"
version = "1.1.0"
group = "dev.zontreck"
archivesBaseName = "libac"
archivesBaseName = "LibAC"
repositories {
// Use Maven Central for resolving dependencies.

View file

@ -4,11 +4,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import dev.zontreck.ariaslib.terminal.Terminal;
public class DelayedExecutorService {
private static final AtomicBoolean RUN = new AtomicBoolean(true);
private static int COUNT = 0;
private static final DelayedExecutorService inst;
private static final Timer repeater;
@ -26,6 +29,24 @@ public class DelayedExecutorService {
}
private DelayedExecutorService(){}
/**
* Stops accepting new tasks, and current ones will abort
*/
public static void stop()
{
RUN.set(false);
}
/**
* Resume accepting new tasks.
*
* NOTE: The task system is set to run by default. This call is only needed if DelayedExecutorService#stop was used previously
*/
public static void start()
{
RUN.set(true);
}
public static DelayedExecutorService getInstance()
{
return inst;
@ -60,9 +81,14 @@ public class DelayedExecutorService {
//EXECUTORS.add(exe);
}
public static boolean isRunning()
{
return RUN.get();
}
public void scheduleRepeating(final Runnable run, int seconds)
{
if(!Terminal.isRunning()) return;
if(!isRunning()) return;
TimerTask task = new TimerTask() {
@Override
@ -82,7 +108,7 @@ public class DelayedExecutorService {
public void onTick()
{
if(!Terminal.isRunning())
if(!isRunning())
{
DelayedExecutorService.stopRepeatingThread();
}