Created
July 27, 2019 15:56
-
-
Save ryohji/fa1b900d16b898e73f778ee3784fc235 to your computer and use it in GitHub Desktop.
Kotlin/Native プロジェクト(サンプル)に Coroutine を追加する
This file contains hidden or 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
diff --git a/build.gradle b/build.gradle | |
index 29bd433..6a89632 100644 | |
--- a/build.gradle | |
+++ b/build.gradle | |
@@ -26,6 +26,9 @@ kotlin { | |
} | |
macosTest { | |
} | |
+ commonMain.dependencies { | |
+ implementation('org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.2.2') | |
+ } | |
} | |
} | |
diff --git a/settings.gradle b/settings.gradle | |
index fed354e..389c940 100644 | |
--- a/settings.gradle | |
+++ b/settings.gradle | |
@@ -1,2 +1,3 @@ | |
rootProject.name = 'native-hello' | |
+enableFeaturePreview('GRADLE_METADATA') | |
diff --git a/src/macosMain/kotlin/sample/SampleMacos.kt b/src/macosMain/kotlin/sample/SampleMacos.kt | |
index 1b82932..12189b0 100644 | |
--- a/src/macosMain/kotlin/sample/SampleMacos.kt | |
+++ b/src/macosMain/kotlin/sample/SampleMacos.kt | |
@@ -1,7 +1,20 @@ | |
package sample | |
+import kotlinx.coroutines.* | |
+ | |
fun hello(): String = "Hello, Kotlin/Native!" | |
-fun main() { | |
- println(hello()) | |
-} | |
\ No newline at end of file | |
+fun main() = runBlocking { | |
+ hello() | |
+ .map { | |
+ async { | |
+ delay(1000) | |
+ it | |
+ } | |
+ } | |
+ .awaitAll() | |
+ .joinToString("") | |
+ .let { | |
+ println(it) | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment