Skip to content

Commit 4b47b9e

Browse files
committed
Allow Runnables to include Futures
1 parent 91fc75f commit 4b47b9e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

build.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
toast.version=1.3.2
1+
toast.version=1.3.3

src/main/java/jaci/openrio/toast/core/thread/ToastThreadPool.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import jaci.openrio.toast.core.ToastConfiguration;
44

5-
import java.util.concurrent.ExecutorService;
6-
import java.util.concurrent.Executors;
7-
import java.util.concurrent.ThreadFactory;
8-
import java.util.concurrent.TimeUnit;
5+
import java.util.concurrent.*;
96
import java.util.concurrent.atomic.AtomicInteger;
107

118
/**
@@ -61,8 +58,18 @@ public static void init() {
6158
* @param runnable The Runnable Instance to trigger when running. This can be an anonymous member, which is the intended
6259
* implementation, although you can extend this interface and it will work just as well.
6360
*/
64-
public void addWorker(Runnable runnable) {
65-
threadPool.execute(runnable);
61+
public Future addWorker(Runnable runnable) {
62+
return threadPool.submit(runnable);
63+
}
64+
65+
/**
66+
* Add a new Worker to the Thread Pool. For basic usage, this is the only function you should call. This will schedule
67+
* a task to run when the Thread is not busy (add it to the queue).
68+
* @param callable The Callable Instance to trigger when running. This can be an anonymous member, which is the intended
69+
* implementation, although you can extend this interface and it will work just as well.
70+
*/
71+
public Future addWorker(Callable callable) {
72+
return threadPool.submit(callable);
6673
}
6774

6875
/**

0 commit comments

Comments
 (0)