Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only throw InterruptedException for blocking APIs #74

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ public fun interface OutputFeed {
* was called (i.e. never started)
* - Has already stopped
*
* **NOTE:** This will always throw [InterruptedException]
* on Node.js. Use [awaitStopAsync].
*
* @return [Process] for chaining calls
* @throws [InterruptedException]
* @throws [UnsupportedOperationException] on Node.js
* @throws [InterruptedException] When:
* - Platform is Node.js
* - Thread this is called from on Native/Jvm was interrupted
* */
@Throws(InterruptedException::class, UnsupportedOperationException::class)
@Throws(InterruptedException::class)
public fun awaitStop(): Process {
while (isStarted() && !isStopped()) {
5.milliseconds.threadSleep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ public abstract class Process internal constructor(
/**
* Blocks the current thread until [Process] completion.
*
* **NOTE:** This will always throw [InterruptedException]
* on Node.js. Use [waitForAsync].
*
* @return The [Process.exitCode]
* @throws [InterruptedException]
* @throws [UnsupportedOperationException] on Node.js
* @throws [InterruptedException] When:
* - Platform is Node.js
* - Thread this is called from on Native/Jvm was interrupted
* */
@Throws(InterruptedException::class, UnsupportedOperationException::class)
@Throws(InterruptedException::class)
public fun waitFor(): Int {
var exitCode: Int? = null
while (exitCode == null) {
Expand All @@ -180,13 +184,17 @@ public abstract class Process internal constructor(
* or until [Process.exitCode] is available (i.e. the
* [Process] completed).
*
* **NOTE:** This will always throw [InterruptedException]
* on Node.js. Use [waitForAsync].
*
* @param [duration] the [Duration] to wait
* @return The [Process.exitCode], or null if [duration] is
* exceeded without [Process] completion.
* @throws [InterruptedException]
* @throws [UnsupportedOperationException] on Node.js
* @throws [InterruptedException] When:
* - Platform is Node.js
* - Thread this is called from on Native/Jvm was interrupted
* */
@Throws(InterruptedException::class, UnsupportedOperationException::class)
@Throws(InterruptedException::class)
public fun waitFor(duration: Duration): Int? = commonWaitFor(duration) { it.threadSleep() }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal expect val IsMobile: Boolean
internal inline val IsWindows: Boolean get() = STDIO_NULL.path == "NUL"

@Suppress("NOTHING_TO_INLINE")
@Throws(InterruptedException::class, UnsupportedOperationException::class)
@Throws(InterruptedException::class)
internal expect inline fun Duration.threadSleep()

internal fun StringBuilder.appendProcessInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ internal actual val IsMobile: Boolean get() = try {
false
}

// @Throws(InterruptedException::class)
@Suppress("NOTHING_TO_INLINE", "ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT")
// @Throws(UnsupportedOperationException::class)
internal actual inline fun Duration.threadSleep() {
throw UnsupportedOperationException("Blocking operations are not supported on Node.js. Use Async APIs or Process.Builder.output")
throw InterruptedException("Blocking operations are not supported on Node.js. Use Async APIs or Process.Builder.output")
}

@Suppress("NOTHING_TO_INLINE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ internal val ANDROID_SDK_INT: Int? by lazy {
}
}

@Suppress("NOTHING_TO_INLINE")
@Throws(InterruptedException::class)
@Suppress("NOTHING_TO_INLINE", "ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT")
internal actual inline fun Duration.threadSleep() {
Thread.sleep(inWholeMilliseconds)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ internal actual val IsMobile: Boolean get() {
}
}

@Suppress("NOTHING_TO_INLINE")
@Throws(InterruptedException::class)
@Suppress("NOTHING_TO_INLINE", "ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT")
internal actual inline fun Duration.threadSleep() {
if (usleep(inWholeMicroseconds.toUInt()) == -1) {
// EINVAL will never happen b/c duration is
Expand Down
Loading