-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af9f5d2
commit e31f2b3
Showing
6 changed files
with
56 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...client-core/src/main/java/net/zscript/javaclient/threading/ZscriptCallbackThreadpool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.zscript.javaclient.threading; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.function.Consumer; | ||
|
||
public class ZscriptCallbackThreadpool { | ||
private final ExecutorService callbackPool; | ||
|
||
public ZscriptCallbackThreadpool() { | ||
this.callbackPool = Executors.newCachedThreadPool(); | ||
} | ||
|
||
public ZscriptCallbackThreadpool(ExecutorService callbackPool) { | ||
this.callbackPool = callbackPool; | ||
} | ||
|
||
public <T> void sendCallback(Consumer<T> callback, T content) { | ||
callbackPool.submit(() -> callback.accept(content)); | ||
} | ||
|
||
public void sendCallback(Runnable callback) { | ||
callbackPool.submit(callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters