This commit is contained in:
huangyuhui
2017-08-27 14:23:27 +08:00
parent 8c61bc1a5e
commit 41337f66a8
7 changed files with 405 additions and 5 deletions

View File

@@ -132,6 +132,7 @@ abstract class Task {
fun executor() = TaskExecutor(this)
fun executor(taskListener: TaskListener) = TaskExecutor(this).apply { this.taskListener = taskListener }
fun start() = executor().start()
fun test() = executor().test()
fun subscribe(subscriber: Task) = TaskExecutor(with(subscriber)).apply { start() }
fun subscribe(scheduler: Scheduler = Scheduler.DEFAULT, closure: (AutoTypingMap<String>) -> Unit) = subscribe(task(scheduler, closure))

View File

@@ -47,6 +47,20 @@ class TaskExecutor(private val task: Task) {
})
}
@Throws(InterruptedException::class)
fun test(): Boolean {
var flag = true
val future = Scheduler.NEW_THREAD.schedule {
if (!executeTasks(listOf(task))) {
taskListener?.onTerminate()
flag = false
}
}
workerQueue.add(future)
future!!.get()
return flag
}
/**
* Cancel the subscription ant interrupt all tasks.
*/

View File

@@ -28,23 +28,23 @@ import java.util.*
/**
* Represents the operating system.
*/
enum class OS {
enum class OS(val checkedName: String) {
/**
* Microsoft Windows.
*/
WINDOWS,
WINDOWS("windows"),
/**
* Linux and Unix like OS, including Solaris.
*/
LINUX,
LINUX("linux"),
/**
* Mac OS X.
*/
OSX,
OSX("osx"),
/**
* Unknown operating system.
*/
UNKNOWN;
UNKNOWN("universal");
companion object {
/**

View File

@@ -75,6 +75,8 @@ class StringVersionNumber internal constructor(val version: String): VersionNumb
*/
class IntVersionNumber internal constructor(val version: List<Int>): VersionNumber() {
operator fun get(index: Int) = version[index]
override fun compareTo(other: VersionNumber): Int {
if (other !is IntVersionNumber) return 0
val len = minOf(this.version.size, other.version.size)