mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 12:22:24 +08:00
JavaPluginSchedulerImpl: run jobs with runInterruptible
This commit is contained in:
parent
3ccc07d5f4
commit
4993e59fd0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -26,7 +26,7 @@ internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineConte
|
||||
override fun repeating(intervalMs: Long, runnable: Runnable): Future<Void?> {
|
||||
return this.future {
|
||||
while (isActive) {
|
||||
withContext(Dispatchers.IO) { runnable.run() }
|
||||
runInterruptible(Dispatchers.IO) { runnable.run() }
|
||||
delay(intervalMs)
|
||||
}
|
||||
null
|
||||
@ -36,7 +36,7 @@ internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineConte
|
||||
override fun delayed(delayMillis: Long, runnable: Runnable): CompletableFuture<Void?> {
|
||||
return future {
|
||||
delay(delayMillis)
|
||||
withContext(Dispatchers.IO) {
|
||||
runInterruptible(Dispatchers.IO) {
|
||||
runnable.run()
|
||||
}
|
||||
null
|
||||
@ -46,19 +46,19 @@ internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineConte
|
||||
override fun <R> delayed(delayMillis: Long, callable: Callable<R>): CompletableFuture<R> {
|
||||
return future {
|
||||
delay(delayMillis)
|
||||
withContext(Dispatchers.IO) { callable.call() }
|
||||
runInterruptible(Dispatchers.IO) { callable.call() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun <R> async(supplier: Callable<R>): Future<R> {
|
||||
return future {
|
||||
withContext(Dispatchers.IO) { supplier.call() }
|
||||
runInterruptible(Dispatchers.IO) { supplier.call() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun async(runnable: Runnable): Future<Void?> {
|
||||
return future {
|
||||
withContext(Dispatchers.IO) { runnable.run() }
|
||||
runInterruptible(Dispatchers.IO) { runnable.run() }
|
||||
null
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user