More careful 1.8 implementation
This commit is contained in:
parent
7958b67617
commit
29f77e5713
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 dorkbox, llc
|
* Copyright 2023 dorkbox, llc
|
||||||
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -32,11 +32,11 @@ import org.slf4j.LoggerFactory
|
||||||
import org.slf4j.MDC
|
import org.slf4j.MDC
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.ExecutionException
|
import java.util.concurrent.*
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import java.util.concurrent.TimeoutException
|
|
||||||
import kotlin.text.Charsets.UTF_8
|
import kotlin.text.Charsets.UTF_8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal data class Params(
|
internal data class Params(
|
||||||
/**
|
/**
|
||||||
* Set of main attributes used to start the process.
|
* Set of main attributes used to start the process.
|
||||||
|
@ -212,7 +212,7 @@ class DeferredProcessResult internal constructor(private val process: Process,
|
||||||
try {
|
try {
|
||||||
// always do this
|
// always do this
|
||||||
waiter.doNotify()
|
waiter.doNotify()
|
||||||
} catch (ignored: CancellationException) {
|
} catch (ignored: Exception) {
|
||||||
// we want to ignore any cancellation exceptions
|
// we want to ignore any cancellation exceptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ class DeferredProcessResult internal constructor(private val process: Process,
|
||||||
withTimeoutOrNull(timeoutUnit.toMillis(timeout)) {
|
withTimeoutOrNull(timeoutUnit.toMillis(timeout)) {
|
||||||
try {
|
try {
|
||||||
waiter.doWait()
|
waiter.doWait()
|
||||||
} catch (ignored: CancellationException) {
|
} catch (ignored: Exception) {
|
||||||
// we want to ignore any cancellation exceptions
|
// we want to ignore any cancellation exceptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,10 +547,18 @@ class DeferredProcessResult internal constructor(private val process: Process,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getUnitsAsString(timeout: Long, timeUnit: TimeUnit): String {
|
private fun getUnitsAsString(timeout: Long, timeUnit: TimeUnit): String {
|
||||||
val result = timeUnit.toChronoUnit().name
|
val result = when (timeUnit) {
|
||||||
return if (timeout == 1L) {
|
TimeUnit.NANOSECONDS -> "nano"
|
||||||
|
TimeUnit.MICROSECONDS -> "micro"
|
||||||
|
TimeUnit.MILLISECONDS -> "milli"
|
||||||
|
TimeUnit.SECONDS -> "second"
|
||||||
|
TimeUnit.MINUTES -> "minute"
|
||||||
|
TimeUnit.HOURS -> "hour"
|
||||||
|
TimeUnit.DAYS -> "day"
|
||||||
|
}
|
||||||
|
return if (timeout > 1L) {
|
||||||
// fix plurality
|
// fix plurality
|
||||||
result.substring(0, result.length - 1)
|
result + "s"
|
||||||
} else {
|
} else {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue