Commit 9e3d1209 authored by liujiahua123123's avatar liujiahua123123

task

parent 9a877b2b
......@@ -12,4 +12,9 @@ public class MiraiTaskManager {
return MiraiTaskManager.instance;
}
private MiraiTaskPool pool;
private MiraiTaskManager(){
}
}
package net.mamoe.mirai.task;
import java.util.concurrent.*;
public class MiraiTaskPool {
ExecutorService service;
protected MiraiTaskPool(){
this.service = Executors.newCachedThreadPool();
}
public <D> Future<D> submit(Callable<D> callable, MiralTaskExceptionHandler handler) {
return this.service.submit(() -> {
try {
return callable.call();
} catch (Throwable e) {
handler.onHandle(e);
return null;
}
});
}
public <D> Future<D> submit(Callable<D> callable) {
return this.submit(callable, Throwable::printStackTrace);
}
}
package net.mamoe.mirai.task;
@FunctionalInterface
public interface MiralTaskExceptionHandler {
void onHandle(Throwable e);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment