mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Clean up.
This commit is contained in:
parent
62f072d6de
commit
1eb9e77a46
1 changed files with 7 additions and 6 deletions
|
@ -11,7 +11,7 @@ class NamedThreadFactory(val n: String) : ThreadFactory {
|
||||||
override
|
override
|
||||||
public fun newThread(r: Runnable) : Thread {
|
public fun newThread(r: Runnable) : Thread {
|
||||||
val result = Thread(r)
|
val result = Thread(r)
|
||||||
result.setName(name + "-" + result.getId())
|
result.name = name + "-" + result.id
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class KobaltExecutor(name: String, threadCount: Int)
|
||||||
var ex : Throwable? = null
|
var ex : Throwable? = null
|
||||||
if (t == null && r is Future<*>) {
|
if (t == null && r is Future<*>) {
|
||||||
try {
|
try {
|
||||||
if (r.isDone()) r.get();
|
if (r.isDone) r.get();
|
||||||
} catch (ce: CancellationException) {
|
} catch (ce: CancellationException) {
|
||||||
ex = ce;
|
ex = ce;
|
||||||
} catch (ee: ExecutionException) {
|
} catch (ee: ExecutionException) {
|
||||||
|
@ -52,8 +52,8 @@ public class KobaltExecutors {
|
||||||
miscExecutor.shutdown()
|
miscExecutor.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> completionService(name: String, threadCount: Int,
|
fun <T> completionService(name: String, threadCount: Int, maxMs: Long, tasks: List<Callable<T>>,
|
||||||
maxMs: Long, tasks: List<Callable<T>>) : List<T> {
|
progress: (T) -> Unit = {}) : List<T> {
|
||||||
val result = arrayListOf<T>()
|
val result = arrayListOf<T>()
|
||||||
val executor = newExecutor(name, threadCount)
|
val executor = newExecutor(name, threadCount)
|
||||||
val cs = ExecutorCompletionService<T>(executor)
|
val cs = ExecutorCompletionService<T>(executor)
|
||||||
|
@ -64,14 +64,15 @@ public class KobaltExecutors {
|
||||||
while (i < tasks.size() && remainingMs >= 0) {
|
while (i < tasks.size() && remainingMs >= 0) {
|
||||||
var start = System.currentTimeMillis()
|
var start = System.currentTimeMillis()
|
||||||
val r = cs.take().get(remainingMs, TimeUnit.MILLISECONDS)
|
val r = cs.take().get(remainingMs, TimeUnit.MILLISECONDS)
|
||||||
|
progress(r)
|
||||||
result.add(r)
|
result.add(r)
|
||||||
remainingMs -= (System.currentTimeMillis() - start)
|
remainingMs -= (System.currentTimeMillis() - start)
|
||||||
log(2, "Received ${r}, remaining: ${remainingMs} ms")
|
log(2, "Received $r, remaining: $remainingMs ms")
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remainingMs < 0) {
|
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 {
|
} else {
|
||||||
log(2, "Received all results in ${maxMs - remainingMs} ms")
|
log(2, "Received all results in ${maxMs - remainingMs} ms")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue