|
13 | 13 | Starting with version <code>0.5.0</code>, the library introduces major changes to the service APIs.
|
14 | 14 | The following declarations will be gradually restricted:
|
15 | 15 | </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<Int> // deprecated |
24 |
| - |
25 |
| - suspend fun new(): Flow<Int> // 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<Int> // deprecated |
36 |
| - |
37 |
| - suspend fun new(): Flow<Int> // 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<Flow<Int>> // 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<Rap>, 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<Rap> |
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<Int> // deprecated |
| 22 | + |
| 23 | + suspend fun new(): Flow<Int> // use .stateIn on the client side |
| 24 | + } |
| 25 | + </code-block> |
| 26 | + </chapter> |
73 | 27 |
|
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<Int> // deprecated |
76 | 34 |
|
77 |
| - @Rpc |
78 |
| - interface Service : RemoteService { |
79 |
| - suspend fun old(): Flow<SpotifyWrapped> // deprecated |
| 35 | + suspend fun new(): Flow<Int> // 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<Flow<Int>> // 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> |
80 | 52 |
|
81 |
| - fun new(): Flow<SpotifyWrapped> |
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<Int>) |
110 |
| - suspend fun oldServer(): Flow<Int> |
111 |
| - } |
| 53 | + <code-block lang="kotlin"> |
| 54 | + data class SpotifyWrapped(val myMusicFlow: Flow<Rap>, val extra: Data) |
112 | 55 |
|
113 |
| - suspend fun consumer(service: Service) { |
114 |
| - streamScoped { |
115 |
| - service.oldClient(flow { /* ... */ } ) |
| 56 | + @Rpc |
| 57 | + interface Service : RemoteService { |
| 58 | + suspend fun old(): SpotifyWrapped // deprecated |
116 | 59 |
|
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<Int>) |
130 |
| - fun newServer(): Flow<Int> |
131 |
| - } |
| 60 | + // one should consider message delivery order when calling these |
| 61 | + suspend fun new(): Flow<Rap> |
| 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) |
132 | 71 |
|
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<SpotifyWrapped> // deprecated |
137 | 75 |
|
138 |
| - flow.collect { |
139 |
| - // ... |
140 |
| - } |
| 76 | + fun new(): Flow<SpotifyWrapped> |
| 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<Int>) |
| 104 | + suspend fun oldServer(): Flow<Int> |
| 105 | + } |
| 106 | + |
| 107 | + suspend fun consumer(service: Service) { |
| 108 | + streamScoped { |
| 109 | + service.oldClient(flow { /* ... */ }) |
| 110 | + |
| 111 | + service.oldServer().collect { |
| 112 | + // ... |
141 | 113 | }
|
142 | 114 | }
|
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<Int>) |
| 124 | + fun newServer(): Flow<Int> |
| 125 | + } |
| 126 | + |
| 127 | + fun consumer(service: Service, scope: CoroutineScope) { |
| 128 | + val flow = service.new() |
| 129 | + scope.launch { |
| 130 | + service.newClient(flow { /* ... */ }) |
146 | 131 |
|
147 |
| - service.new().collect { |
| 132 | + flow.collect { |
148 | 133 | // ...
|
149 | 134 | }
|
150 | 135 | }
|
151 |
| - </code-block> |
152 |
| - </li> |
153 |
| - </list> |
| 136 | + } |
154 | 137 |
|
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"> |
159 | 154 | // build.gradle.kts
|
160 | 155 | plugins {
|
161 | 156 | id("org.jetbrains.kotlinx.rpc.plugin")
|
|
173 | 168 | }
|
174 | 169 | }
|
175 | 170 | </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> |
185 | 181 | </topic>
|
0 commit comments