|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
| 2 | +<!-- |
| 3 | + - Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 4 | + --> |
| 5 | + |
2 | 6 | <!DOCTYPE topic
|
3 | 7 | SYSTEM "https://resources.jetbrains.com/writerside/1.0/xhtml-entities.dtd">
|
4 | 8 | <topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
63 | 67 | }
|
64 | 68 | </code-block>
|
65 | 69 | </li>
|
| 70 | + <li> |
| 71 | + <b>Non-suspending server flows</b> |
| 72 | + <p>Deprecation level: <code>WARNING</code></p> |
| 73 | + |
| 74 | + <code-block lang="kotlin"> |
| 75 | + data class SpotifyWrapped(val extra: Data) |
| 76 | + |
| 77 | + @Rpc |
| 78 | + interface Service : RemoteService { |
| 79 | + suspend fun old(): Flow<SpotifyWrapped> // deprecated |
| 80 | + |
| 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 | + } |
| 112 | + |
| 113 | + suspend fun consumer(service: Service) { |
| 114 | + streamScoped { |
| 115 | + service.oldClient(flow { /* ... */ } ) |
| 116 | + |
| 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 | + } |
| 132 | + |
| 133 | + fun consumer(service: Service, scope: CoroutineScope) { |
| 134 | + val flow = service.new() |
| 135 | + scope.launch { |
| 136 | + service.newClient(flow { /* ... */ } ) |
| 137 | + |
| 138 | + flow.collect { |
| 139 | + // ... |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + // or |
| 144 | + suspend fun consumer(service: Service) { |
| 145 | + service.newClient(flow { /* ... */ } ) |
| 146 | + |
| 147 | + service.new().collect { |
| 148 | + // ... |
| 149 | + } |
| 150 | + } |
| 151 | + </code-block> |
| 152 | + </li> |
66 | 153 | </list>
|
67 | 154 |
|
68 | 155 | <p>
|
|
81 | 168 | nestedFlow = RpcStrictMode.WARNING
|
82 | 169 | notTopLevelServerFlow = RpcStrictMode.WARNING
|
83 | 170 | fields = RpcStrictMode.WARNING
|
| 171 | + suspendingServerStreaming = RpcStrictMode.WARNING |
| 172 | + streamScopedFunctions = RpcStrictMode.WARNING |
84 | 173 | }
|
85 | 174 | }
|
86 | 175 | </code-block>
|
|
90 | 179 |
|
91 | 180 | <warning>
|
92 | 181 | Note that setting <code>RpcStrictMode.NONE</code> should not be done permanently.
|
93 |
| - All deprecated APIs will become errors in future without an option to suppress it. |
| 182 | + All deprecated APIs will become errors in the future without an option to suppress them. |
94 | 183 | Consider your migration path in advance.
|
95 | 184 | </warning>
|
96 | 185 | </topic>
|
0 commit comments