Skip to content

Commit a2e9c0f

Browse files
committed
Update samples tp 0.6.1 (#319)
1 parent e216ac7 commit a2e9c0f

File tree

26 files changed

+93
-103
lines changed

26 files changed

+93
-103
lines changed

samples/ktor-all-platforms-app/composeApp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ plugins {
1313
alias(libs.plugins.androidApplication)
1414
alias(libs.plugins.jetbrainsCompose)
1515
alias(libs.plugins.compose.compiler)
16+
alias(libs.plugins.kotlinx.rpc)
1617
}
1718

1819
kotlin {

samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ fun App() {
6666
}
6767

6868
LaunchedEffect(service) {
69-
streamScoped {
70-
service.subscribeToNews().collect { article ->
71-
news.add(article)
72-
}
69+
service.subscribeToNews().collect { article ->
70+
news.add(article)
7371
}
7472
}
7573

samples/ktor-all-platforms-app/gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
kotlin = "2.1.10"
2+
kotlin = "2.1.20"
33

44
agp = "8.8.0-alpha05"
55
android-compileSdk = "35"
@@ -19,7 +19,7 @@ ktor = "3.0.3"
1919
logback = "1.5.16"
2020
serialization = "1.8.0"
2121
coroutines = "1.10.1"
22-
kotlinx-rpc = "0.5.1"
22+
kotlinx-rpc = "0.6.1"
2323

2424
[libraries]
2525
# kotlin

samples/ktor-all-platforms-app/server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
plugins {
66
alias(libs.plugins.kotlinJvm)
77
alias(libs.plugins.ktor)
8+
alias(libs.plugins.kotlinx.rpc)
89
application
910
}
1011

samples/ktor-all-platforms-app/server/src/main/kotlin/kotlinx/rpc/sample/UserServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UserServiceImpl(override val coroutineContext: CoroutineContext) : UserSer
1616
return "Nice to meet you $user, how is it in ${userData.address}?"
1717
}
1818

19-
override suspend fun subscribeToNews(): Flow<String> {
19+
override fun subscribeToNews(): Flow<String> {
2020
return flow {
2121
repeat(10) {
2222
delay(300)

samples/ktor-all-platforms-app/server/src/test/kotlin/kotlinx/rpc/sample/ApplicationTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ class ApplicationTest {
3535
actual = service.hello("Alex", UserData("address1", "last")),
3636
)
3737

38-
streamScoped {
39-
assertEquals(
40-
expected = List(10) { "Article number $it" },
41-
actual = service.subscribeToNews().toList(),
42-
)
43-
}
38+
assertEquals(
39+
expected = List(10) { "Article number $it" },
40+
actual = service.subscribeToNews().toList(),
41+
)
4442
}
4543
}

samples/ktor-all-platforms-app/shared/src/commonMain/kotlin/UserService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ data class UserData(
1717
interface UserService : RemoteService {
1818
suspend fun hello(user: String, userData: UserData): String
1919

20-
suspend fun subscribeToNews(): Flow<String>
20+
fun subscribeToNews(): Flow<String>
2121
}

samples/ktor-android-app/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
alias(libs.plugins.kotlinAndroid)
88
alias(libs.plugins.kotlinPluginSerialization)
99
alias(libs.plugins.compose.compiler)
10+
alias(libs.plugins.kotlinx.rpc)
1011
}
1112

1213
android {

samples/ktor-android-app/app/src/main/kotlin/kotlinx/rpc/sample/ui/AppViewModel.kt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,23 @@ class AppViewModel : ViewModel() {
3939

4040
private fun fetchData() {
4141
viewModelScope.launch(Dispatchers.IO) {
42-
streamScoped {
43-
delay(2000)
44-
val greetingDeferred = async {
45-
apiService?.hello(
46-
"Alex",
47-
UserData("Berlin", "Smith")
48-
)
49-
}
50-
val newsDeferred = async { apiService?.subscribeToNews() }
42+
delay(2000)
43+
val greetingDeferred = async {
44+
apiService?.hello(
45+
"Alex",
46+
UserData("Berlin", "Smith")
47+
)
48+
}
5149

52-
val serverGreeting = greetingDeferred.await()
53-
val news = newsDeferred.await()
50+
val serverGreeting = greetingDeferred.await()
5451

55-
val allNews: MutableList<String> = mutableListOf()
56-
news?.collect {
57-
allNews += it
52+
val allNews: MutableList<String> = mutableListOf()
53+
apiService?.subscribeToNews()?.collect {
54+
allNews += it
5855

59-
val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
60-
serverGreeting?.let {
61-
_uiState.value = WelcomeData(serverGreeting, sendNews)
62-
}
56+
val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
57+
serverGreeting?.let {
58+
_uiState.value = WelcomeData(serverGreeting, sendNews)
6359
}
6460
}
6561
}

samples/ktor-android-app/common/src/main/kotlin/kotlinx/rpc/sample/MyService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ import kotlinx.rpc.annotations.Rpc
1212
interface MyService : RemoteService {
1313
suspend fun hello(user: String, userData: UserData): String
1414

15-
suspend fun subscribeToNews(): Flow<String>
15+
fun subscribeToNews(): Flow<String>
1616
}

0 commit comments

Comments
 (0)