File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed
okio/src/jvmMain/kotlin/okio Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -161,27 +161,21 @@ actual open class Timeout {
161
161
}
162
162
163
163
// Compute how long we'll wait.
164
- val start = System .nanoTime()
165
164
val waitNanos = if (hasDeadline && timeoutNanos != 0L ) {
166
- val deadlineNanos = deadlineNanoTime() - start
165
+ val deadlineNanos = deadlineNanoTime() - System .nanoTime()
167
166
minOf(timeoutNanos, deadlineNanos)
168
167
} else if (hasDeadline) {
169
- deadlineNanoTime() - start
168
+ deadlineNanoTime() - System .nanoTime()
170
169
} else {
171
170
timeoutNanos
172
171
}
173
172
174
- // Attempt to wait that long. This will break out early if the monitor is notified.
175
- var elapsedNanos = 0L
176
- if (waitNanos > 0L ) {
177
- condition.await(waitNanos, TimeUnit .NANOSECONDS )
178
- elapsedNanos = System .nanoTime() - start
179
- }
173
+ if (waitNanos <= 0 ) throw InterruptedIOException (" timeout" )
180
174
181
- // Throw if the timeout elapsed before the monitor was notified.
182
- if (elapsedNanos >= waitNanos) {
183
- throw InterruptedIOException ( " timeout " )
184
- }
175
+ // Attempt to wait that long. This will return early if the monitor is notified.
176
+ val nanosRemaining = condition.awaitNanos( waitNanos)
177
+
178
+ if (nanosRemaining <= 0 ) throw InterruptedIOException ( " timeout " )
185
179
} catch (e: InterruptedException ) {
186
180
Thread .currentThread().interrupt() // Retain interrupted status.
187
181
throw InterruptedIOException (" interrupted" )
You can’t perform that action at this time.
0 commit comments