diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt b/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt index c767bd1a..73180f14 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt @@ -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 completionService(name: String, threadCount: Int, - maxMs: Long, tasks: List>) : List { + fun completionService(name: String, threadCount: Int, maxMs: Long, tasks: List>, + progress: (T) -> Unit = {}) : List { val result = arrayListOf() val executor = newExecutor(name, threadCount) val cs = ExecutorCompletionService(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") }