Skip to content

Commit 4337fd6

Browse files
committed
Review comments
1 parent 0a7d5ff commit 4337fd6

File tree

3 files changed

+138
-141
lines changed

3 files changed

+138
-141
lines changed

docs/pages/kotlinx-rpc/topics/0-6-0.topic

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
title="Migration to 0.6.0" id="0-6-0">
1111

1212
<p>
13-
Version <code>0.6.0</code> introduces non-breaking changes, that require migration.
13+
Version <code>0.6.0</code> introduces non-breaking changes that require migration.
1414
</p>
1515

1616
<chapter title="Non-suspending flows" id="non-suspending-flows">
1717
<p>
1818
Non-suspending server flows are now supported.
1919
That begins the deprecation cycle for the suspending server flows and stream scopes.
20-
Please refer to the <a href="strict-mode.topic"/> section for more details on the migration
21-
(sections <code>Non-suspending server flows</code> and <code>Stream scopes management</code>).
20+
For more details, refer to the Non-suspending server flows and Stream scopes management
21+
sections in the <a href="strict-mode.topic"/> topic.
2222
</p>
2323
</chapter>
2424
</topic>

docs/pages/kotlinx-rpc/topics/strict-mode.topic

Lines changed: 134 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -13,149 +13,144 @@
1313
Starting with version <code>0.5.0</code>, the library introduces major changes to the service APIs.
1414
The following declarations will be gradually restricted:
1515
</p>
16-
<list>
17-
<li>
18-
<b><code>StateFlow</code> and <code>SharedFlow</code></b>
19-
<p>Deprecation level: <code>WARNING</code></p>
20-
<code-block lang="kotlin">
21-
@Rpc
22-
interface Service : RemoteService {
23-
suspend fun old(): StateFlow&lt;Int&gt; // deprecated
24-
25-
suspend fun new(): Flow&lt;Int&gt; // use .stateIn on the client side
26-
}
27-
</code-block>
28-
</li>
29-
<li>
30-
<b>Fields</b>
31-
<p>Deprecation level: <code>WARNING</code></p>
32-
<code-block lang="kotlin">
33-
@Rpc
34-
interface Service : RemoteService {
35-
val old: Flow&lt;Int&gt; // deprecated
36-
37-
suspend fun new(): Flow&lt;Int&gt; // store flow locally
38-
}
39-
</code-block>
40-
</li>
41-
<li>
42-
<b>Nested Flows</b>
43-
<p>Deprecation level: <code>WARNING</code></p>
44-
<code-block lang="kotlin">
45-
@Rpc
46-
interface Service : RemoteService {
47-
suspend fun old(): Flow&lt;Flow&lt;Int&gt;&gt; // deprecated
48-
49-
// no particular alternative, depends on the use case
50-
}
51-
</code-block>
52-
</li>
53-
<li>
54-
<b>Not top-level server flows</b>
55-
<p>Deprecation level: <code>WARNING</code></p>
56-
57-
<code-block lang="kotlin">
58-
data class SpotifyWrapped(val myMusicFlow: Flow&lt;Rap&gt;, val extra: Data)
59-
60-
@Rpc
61-
interface Service : RemoteService {
62-
suspend fun old(): SpotifyWrapped // deprecated
63-
64-
// one should consider message delivery order when calling these
65-
suspend fun new(): Flow&lt;Rap&gt;
66-
suspend fun getData(): Data
67-
}
68-
</code-block>
69-
</li>
70-
<li>
71-
<b>Non-suspending server flows</b>
72-
<p>Deprecation level: <code>WARNING</code></p>
16+
<chapter title="StateFlow and SharedFlow" id="stateflow-and-sharedflow">
17+
<p>Deprecation level: <code>WARNING</code></p>
18+
<code-block lang="kotlin">
19+
@Rpc
20+
interface Service : RemoteService {
21+
suspend fun old(): StateFlow&lt;Int&gt; // deprecated
22+
23+
suspend fun new(): Flow&lt;Int&gt; // use .stateIn on the client side
24+
}
25+
</code-block>
26+
</chapter>
7327

74-
<code-block lang="kotlin">
75-
data class SpotifyWrapped(val extra: Data)
28+
<chapter title="Fields" id="fields">
29+
<p>Deprecation level: <code>WARNING</code></p>
30+
<code-block lang="kotlin">
31+
@Rpc
32+
interface Service : RemoteService {
33+
val old: Flow&lt;Int&gt; // deprecated
7634

77-
@Rpc
78-
interface Service : RemoteService {
79-
suspend fun old(): Flow&lt;SpotifyWrapped&gt; // deprecated
35+
suspend fun new(): Flow&lt;Int&gt; // store flow locally
36+
}
37+
</code-block>
38+
</chapter>
39+
<chapter title="Nested Flows" id="nested-flows">
40+
<p>Deprecation level: <code>WARNING</code></p>
41+
<code-block lang="kotlin">
42+
@Rpc
43+
interface Service : RemoteService {
44+
suspend fun old(): Flow&lt;Flow&lt;Int&gt;&gt; // deprecated
45+
46+
// no particular alternative, depends on the use case
47+
}
48+
</code-block>
49+
</chapter>
50+
<chapter title="Not top-level server flows" id="not-top-level-server-flows">
51+
<p>Deprecation level: <code>WARNING</code></p>
8052

81-
fun new(): Flow&lt;SpotifyWrapped&gt;
82-
}
83-
</code-block>
84-
</li>
85-
<li>
86-
<b>Stream scopes management</b>
87-
<p>Deprecation level: <code>WARNING</code></p>
88-
89-
<p>
90-
The next stream scope management structures are deprecated due to the introduction of
91-
non-suspending server flows:
92-
</p>
93-
<list>
94-
<li><code>StreamScoped</code> class and function</li>
95-
<li><code>streamScoped</code> function</li>
96-
<li><code>invokeOnStreamScopeCompletion</code> function</li>
97-
<li><code>withStreamScope</code> function</li>
98-
</list>
99-
<p>
100-
Stream collection and completion is now bound to the <code>CoroutineScope</code> in which the flow was
101-
collected (server-side flows) or produced (client-side flows).
102-
</p>
103-
<p>
104-
Old code:
105-
</p>
106-
<code-block lang="kotlin">
107-
@Rpc
108-
interface Service : RemoteService {
109-
suspend fun oldClient(flow: Flow&lt;Int&gt;)
110-
suspend fun oldServer(): Flow&lt;Int&gt;
111-
}
53+
<code-block lang="kotlin">
54+
data class SpotifyWrapped(val myMusicFlow: Flow&lt;Rap&gt;, val extra: Data)
11255

113-
suspend fun consumer(service: Service) {
114-
streamScoped {
115-
service.oldClient(flow { /* ... */ } )
56+
@Rpc
57+
interface Service : RemoteService {
58+
suspend fun old(): SpotifyWrapped // deprecated
11659

117-
service.oldServer().collect {
118-
// ...
119-
}
120-
}
121-
}
122-
</code-block>
123-
<p>
124-
New code:
125-
</p>
126-
<code-block lang="kotlin">
127-
@Rpc
128-
interface Service : RemoteService {
129-
suspend fun newClient(flow: Flow&lt;Int&gt;)
130-
fun newServer(): Flow&lt;Int&gt;
131-
}
60+
// one should consider message delivery order when calling these
61+
suspend fun new(): Flow&lt;Rap&gt;
62+
suspend fun getData(): Data
63+
}
64+
</code-block>
65+
</chapter>
66+
<chapter title="Non-suspending server flows" id="non-suspending-server-flows">
67+
<p>Deprecation level: <code>WARNING</code></p>
68+
69+
<code-block lang="kotlin">
70+
data class SpotifyWrapped(val extra: Data)
13271

133-
fun consumer(service: Service, scope: CoroutineScope) {
134-
val flow = service.new()
135-
scope.launch {
136-
service.newClient(flow { /* ... */ } )
72+
@Rpc
73+
interface Service : RemoteService {
74+
suspend fun old(): Flow&lt;SpotifyWrapped&gt; // deprecated
13775

138-
flow.collect {
139-
// ...
140-
}
76+
fun new(): Flow&lt;SpotifyWrapped&gt;
77+
}
78+
</code-block>
79+
</chapter>
80+
<chapter title="Stream scopes management" id="stream-scopes-management">
81+
<p>Deprecation level: <code>WARNING</code></p>
82+
83+
<p>
84+
The next stream scope management structures are deprecated due to the introduction of
85+
non-suspending server flows:
86+
</p>
87+
<list>
88+
<li><code>StreamScoped</code> class and function</li>
89+
<li><code>streamScoped</code> function</li>
90+
<li><code>invokeOnStreamScopeCompletion</code> function</li>
91+
<li><code>withStreamScope</code> function</li>
92+
</list>
93+
<p>
94+
Stream collection and completion is now bound to the <code>CoroutineScope</code> in which the flow was
95+
collected (server-side flows) or produced (client-side flows).
96+
</p>
97+
<p>
98+
0.5.x:
99+
</p>
100+
<code-block lang="kotlin">
101+
@Rpc
102+
interface Service : RemoteService {
103+
suspend fun oldClient(flow: Flow&lt;Int&gt;)
104+
suspend fun oldServer(): Flow&lt;Int&gt;
105+
}
106+
107+
suspend fun consumer(service: Service) {
108+
streamScoped {
109+
service.oldClient(flow { /* ... */ })
110+
111+
service.oldServer().collect {
112+
// ...
141113
}
142114
}
143-
// or
144-
suspend fun consumer(service: Service) {
145-
service.newClient(flow { /* ... */ } )
115+
}
116+
</code-block>
117+
<p>
118+
0.6.x:
119+
</p>
120+
<code-block lang="kotlin">
121+
@Rpc
122+
interface Service : RemoteService {
123+
suspend fun newClient(flow: Flow&lt;Int&gt;)
124+
fun newServer(): Flow&lt;Int&gt;
125+
}
126+
127+
fun consumer(service: Service, scope: CoroutineScope) {
128+
val flow = service.new()
129+
scope.launch {
130+
service.newClient(flow { /* ... */ })
146131

147-
service.new().collect {
132+
flow.collect {
148133
// ...
149134
}
150135
}
151-
</code-block>
152-
</li>
153-
</list>
136+
}
154137

155-
<p>
156-
Deprecation levels are controlled by the Gradle <code>rpc</code> extension:
157-
</p>
158-
<code-block lang="Kotlin">
138+
// or
139+
suspend fun consumer(service: Service) {
140+
service.newClient(flow { /* ... */ })
141+
142+
service.new().collect {
143+
// ...
144+
}
145+
}
146+
</code-block>
147+
</chapter>
148+
149+
<chapter title="Gradle settings" id="gradle-settings">
150+
<p>
151+
Deprecation levels are controlled by the Gradle <code>rpc</code> extension:
152+
</p>
153+
<code-block lang="Kotlin">
159154
// build.gradle.kts
160155
plugins {
161156
id("org.jetbrains.kotlinx.rpc.plugin")
@@ -173,13 +168,14 @@
173168
}
174169
}
175170
</code-block>
176-
<p>
177-
Modes <code>RpcStrictMode.NONE</code> and <code>RpcStrictMode.ERROR</code> are available.
178-
</p>
179-
180-
<warning>
181-
Note that setting <code>RpcStrictMode.NONE</code> should not be done permanently.
182-
All deprecated APIs will become errors in the future without an option to suppress them.
183-
Consider your migration path in advance.
184-
</warning>
171+
<p>
172+
Modes <code>RpcStrictMode.NONE</code> and <code>RpcStrictMode.ERROR</code> are available.
173+
</p>
174+
175+
<warning>
176+
Note that setting <code>RpcStrictMode.NONE</code> should not be done permanently.
177+
All deprecated APIs will become errors in the future without an option to suppress them.
178+
Consider your migration path in advance.
179+
</warning>
180+
</chapter>
185181
</topic>

krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ public abstract class KrpcClient(
355355
} catch (e: CancellationException) {
356356
// sendCancellation is not suspending, so no need for NonCancellable
357357
sendCancellation(CancellationType.REQUEST, call.serviceId.toString(), callId)
358+
connector.unsubscribeFromMessages(call.descriptor.fqName, callId)
358359

359360
throw e
360361
}

0 commit comments

Comments
 (0)