Skip to content

Commit 79a2c2a

Browse files
committed
chore: do format
1 parent a31ea0e commit 79a2c2a

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
package org.javacs.kt.util
22

3-
import org.javacs.kt.LOG
4-
import java.time.Duration
5-
import java.util.function.Supplier
63
import java.util.concurrent.CompletableFuture
74
import java.util.concurrent.Executors
85
import java.util.concurrent.TimeUnit
6+
import java.util.function.Supplier
7+
import org.javacs.kt.LOG
98

109
private var threadCount = 0
1110

1211
class AsyncExecutor {
13-
private val workerThread = Executors.newSingleThreadExecutor { Thread(it, "async${threadCount++}") }
12+
private val workerThread =
13+
Executors.newSingleThreadExecutor { Thread(it, "async${threadCount++}") }
1414

1515
fun execute(task: () -> Unit): CompletableFuture<Void> =
16-
CompletableFuture.runAsync(Runnable(task), workerThread)
16+
CompletableFuture.runAsync(Runnable(task), workerThread)
1717

18-
fun <R> compute(task: () -> R): CompletableFuture<R> =
19-
CompletableFuture.supplyAsync(Supplier(task), workerThread)
18+
fun <R> compute(task: () -> R): CompletableFuture<R> =
19+
CompletableFuture.supplyAsync(Supplier(task), workerThread)
2020

21-
fun <R> computeOr(defaultValue: R, task: () -> R?) =
22-
CompletableFuture.supplyAsync(Supplier {
23-
try {
24-
task() ?: defaultValue
25-
} catch (e: Exception) {
26-
defaultValue
27-
}
28-
}, workerThread)
21+
fun <R> computeOr(defaultValue: R, task: () -> R?) =
22+
CompletableFuture.supplyAsync(
23+
Supplier {
24+
try {
25+
task() ?: defaultValue
26+
} catch (e: Exception) {
27+
defaultValue
28+
}
29+
},
30+
workerThread
31+
)
2932

30-
fun shutdown(awaitTermination: Boolean) {
31-
workerThread.shutdown()
32-
if (awaitTermination) {
33-
LOG.info("Awaiting async termination...")
34-
workerThread.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS)
35-
}
36-
}
33+
fun shutdown(awaitTermination: Boolean) {
34+
workerThread.shutdown()
35+
if (awaitTermination) {
36+
LOG.info("Awaiting async termination...")
37+
workerThread.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS)
38+
}
39+
}
3740
}

0 commit comments

Comments
 (0)