-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from arrow-kt/exit-process
Split platform code into Process interface, automatically call exit for 0 & -1
- Loading branch information
Showing
24 changed files
with
382 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,5 @@ _site/ | |
.sass-cache/ | ||
.jekyll-cache/ | ||
.jekyll-metadata | ||
|
||
.kotlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
public final class arrow/continuations/SuspendAppKt { | ||
public static final fun SuspendApp-8Mi8wO0 (Lkotlin/coroutines/CoroutineContext;JLkotlin/jvm/functions/Function2;)V | ||
public static synthetic fun SuspendApp-8Mi8wO0$default (Lkotlin/coroutines/CoroutineContext;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V | ||
public final class arrow/continuations/Enviroment_jvmKt { | ||
public static final fun process ()Larrow/continuations/Process; | ||
} | ||
|
||
public final class arrow/continuations/JvmProcess : arrow/continuations/Process { | ||
public static final field INSTANCE Larrow/continuations/JvmProcess; | ||
public fun close ()V | ||
public fun exit (I)Ljava/lang/Void; | ||
public synthetic fun exit (I)V | ||
public fun onShutdown (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; | ||
public fun onSigInt (Lkotlin/jvm/functions/Function2;)V | ||
public fun onSigTerm (Lkotlin/jvm/functions/Function2;)V | ||
public fun runScope (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)V | ||
} | ||
|
||
public final class arrow/continuations/unsafe/Unsafe { | ||
public static final field INSTANCE Larrow/continuations/unsafe/Unsafe; | ||
public final fun onShutdown (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function0; | ||
public final fun runCoroutineScope (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)V | ||
public abstract interface class arrow/continuations/Process : java/lang/AutoCloseable { | ||
public abstract fun close ()V | ||
public abstract fun exit (I)V | ||
public abstract fun onShutdown (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; | ||
public abstract fun onSigInt (Lkotlin/jvm/functions/Function2;)V | ||
public abstract fun onSigTerm (Lkotlin/jvm/functions/Function2;)V | ||
public abstract fun runScope (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)V | ||
} | ||
|
||
public final class arrow/continuations/SuspendAppKt { | ||
public static final fun SuspendApp-1Y68eR8 (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;JLarrow/continuations/Process;Lkotlin/jvm/functions/Function2;)V | ||
public static synthetic fun SuspendApp-1Y68eR8$default (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;JLarrow/continuations/Process;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.RELEASE | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
kotlin { | ||
// TODO fix setup for Main-Class | ||
// jvm() | ||
js(IR) { | ||
nodejs { | ||
binaries.executable() | ||
jvm { | ||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
mainRun { | ||
mainClass.set("io.arrow.suspendapp.example.MaintKt") | ||
} | ||
withJava() | ||
} | ||
|
||
linuxX64 { | ||
binaries.executable() | ||
} | ||
mingwX64 { | ||
binaries.executable() | ||
} | ||
macosArm64 { | ||
js(IR) { | ||
nodejs() | ||
binaries.executable() | ||
} | ||
macosX64 { | ||
binaries.executable() | ||
|
||
listOf( | ||
linuxX64(), | ||
mingwX64(), | ||
macosArm64(), | ||
macosX64() | ||
).forEach { target -> | ||
target.binaries.executable(listOf(RELEASE)) { | ||
entryPoint = "io.arrow.suspendapp.example.main" | ||
} | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(project.rootProject) | ||
implementation("io.arrow-kt:arrow-fx-coroutines:1.2.0") | ||
} | ||
} | ||
// val jvmMain by getting | ||
|
||
val jvmMain by getting | ||
val jsMain by getting | ||
val mingwX64Main by getting | ||
val linuxX64Main by getting | ||
val macosArm64Main by getting | ||
val macosX64Main by getting | ||
|
||
create("nativeMain") { | ||
dependsOn(commonMain) | ||
mingwX64Main.dependsOn(this) | ||
linuxX64Main.dependsOn(this) | ||
macosArm64Main.dependsOn(this) | ||
macosX64Main.dependsOn(this) | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
example/src/commonMain/kotlin/Main.kt → ...otlin/io/arrow/suspendapp/example/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# Package definitions | ||
projects.group=io.arrow-kt | ||
|
||
# Pomfile definitions | ||
pom.name=suspendapp | ||
pom.description=Reason about resource-safety in the same way you reason about Structured Concurrency with SuspendApp! | ||
pom.url=https://github.com/arrow-kt/suspendapp/ | ||
|
@@ -13,17 +11,8 @@ pom.smc.url=https://github.com/arrow-kt/arrow/ | |
pom.smc.connection=scm:git:git://github.com/arrow-kt/arrow.git | ||
pom.smc.developerConnection=scm:git:ssh://[email protected]/arrow-kt/arrow.git | ||
|
||
# Gradle options | ||
org.gradle.jvmargs=-Xmx4g | ||
org.gradle.parallel=true | ||
|
||
# To disable publishing of sha-512 checksums for maven-metadata.xml files | ||
systemProp.org.gradle.internal.publish.checksums.insecure=true | ||
|
||
# Kotlin configuration | ||
kotlin.incremental=true | ||
kotlin.code.style=official | ||
kotlin.mpp.enableCompatibilityMetadataVariant=true | ||
kotlin.native.enableDependencyPropagation=false | ||
kotlin.js.generate.executable.default=false | ||
kotlin.native.binary.memoryModel=experimental |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package arrow.continuations | ||
|
||
import kotlin.coroutines.CoroutineContext | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
/** KMP constructor for [Process]. */ | ||
expect fun process(): Process | ||
|
||
/** | ||
* [Process] offers a common API to work with our application's process, installing signal handlers, | ||
* shutdown hooks, running scopes in our process (runBlocking), and exiting the process. | ||
*/ | ||
@OptIn(ExperimentalStdlibApi::class) | ||
interface Process : AutoCloseable { | ||
fun onSigTerm(block: suspend (code: Int) -> Unit): Unit | ||
|
||
fun onSigInt(block: suspend (code: Int) -> Unit): Unit | ||
|
||
fun onShutdown(block: suspend () -> Unit): suspend () -> Unit | ||
|
||
/** | ||
* On JVM, and Native this will use kotlinx.coroutines.runBlocking, On NodeJS we need an infinite | ||
* heartbeat to keep main alive. The heartbeat is fast enough that it isn't silently discarded, as | ||
* longer ticks are, but slow enough that we don't interrupt often. | ||
* https://stackoverflow.com/questions/23622051/how-to-forcibly-keep-a-node-js-process-from-terminating | ||
*/ | ||
fun runScope( | ||
context: CoroutineContext, | ||
block: suspend CoroutineScope.() -> Unit, | ||
) | ||
|
||
fun exit(code: Int): Unit | ||
|
||
override fun close(): Unit | ||
} |
Oops, something went wrong.