Improve Java Scheduler Task

This commit is contained in:
jiahua.liu 2020-04-04 21:17:26 +08:00
parent 8adeb3f04d
commit 20c5b5334d
2 changed files with 25 additions and 1 deletions

View File

@ -5,8 +5,32 @@ package net.mamoe.mirai.console.scheduler;
* 使用kt实现, java的API
*/
/**
* PluginScheduler.RepeatTaskReceipt repeatTaskReceipt = this.getScheduler().repeat(() -> {
* getLogger().info("I repeat");
* },100);
*
*
* this.getScheduler().delay(() -> {
* repeatTaskReceipt.setCancelled(true);
* },10000);
*
*
* Future<String> future = this.getScheduler().async(() -> {
* //do some task
* return "success";
* });
*
* try {
* getLogger().info(future.get());
* } catch (InterruptedException | ExecutionException e) {
* e.printStackTrace();
* }
*/
public class SchedulerTaskManager {
public static SchedulerTaskManagerInstance getInstance(){
return SchedulerTaskManagerInstance.INSTANCE;
}
}

View File

@ -43,7 +43,7 @@ class PluginScheduler(_coroutineContext: CoroutineContext) :CoroutineScope{
override val coroutineContext: CoroutineContext = SupervisorJob() + _coroutineContext
data class RepeatTaskReceipt(@Volatile var cancelled:Boolean = false)
class RepeatTaskReceipt(@Volatile var cancelled:Boolean = false)
/**
* 新增一个Repeat Task(定时任务)
*