1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Clean up.

This commit is contained in:
Cedric Beust 2015-10-14 23:35:31 -07:00
parent 62f072d6de
commit 1eb9e77a46

View file

@ -11,7 +11,7 @@ class NamedThreadFactory(val n: String) : ThreadFactory {
override
public fun newThread(r: Runnable) : Thread {
val result = Thread(r)
result.setName(name + "-" + result.getId())
result.name = name + "-" + result.id
return result
}
}
@ -25,7 +25,7 @@ class KobaltExecutor(name: String, threadCount: Int)
var ex : Throwable? = null
if (t == null && r is Future<*>) {
try {
if (r.isDone()) r.get();
if (r.isDone) r.get();
} catch (ce: CancellationException) {
ex = ce;
} catch (ee: ExecutionException) {
@ -52,8 +52,8 @@ public class KobaltExecutors {
miscExecutor.shutdown()
}
fun <T> completionService(name: String, threadCount: Int,
maxMs: Long, tasks: List<Callable<T>>) : List<T> {
fun <T> completionService(name: String, threadCount: Int, maxMs: Long, tasks: List<Callable<T>>,
progress: (T) -> Unit = {}) : List<T> {
val result = arrayListOf<T>()
val executor = newExecutor(name, threadCount)
val cs = ExecutorCompletionService<T>(executor)
@ -64,14 +64,15 @@ public class KobaltExecutors {
while (i < tasks.size() && remainingMs >= 0) {
var start = System.currentTimeMillis()
val r = cs.take().get(remainingMs, TimeUnit.MILLISECONDS)
progress(r)
result.add(r)
remainingMs -= (System.currentTimeMillis() - start)
log(2, "Received ${r}, remaining: ${remainingMs} ms")
log(2, "Received $r, remaining: $remainingMs ms")
i++
}
if (remainingMs < 0) {
warn("Didn't receive all the results in time: ${i} / ${tasks.size()}")
warn("Didn't receive all the results in time: $i / ${tasks.size()}")
} else {
log(2, "Received all results in ${maxMs - remainingMs} ms")
}