Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Jan 17, 2025
1 parent 52e27f0 commit 5ce1f7d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
25 changes: 13 additions & 12 deletions docs/pages/kotlinx-rpc/topics/annotation-type-safety.topic
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
title="Annotation type-safety" id="annotation-type-safety">

<p>
Library introduces a concept of annotation type-safety. Consider the following example:
The library introduces a concept of annotation type-safety. Consider the following example:
</p>
<code-block lang="Kotlin">
@Rpc
Expand All @@ -17,14 +17,15 @@
fun &lt;T : RemoteService&gt; withService() {}
</code-block>
<p>
Compiler can not guarantee, that the passed type is the one for which the code generation was run:
Compiler can not guarantee, that the passed type parameter is the one for which the code generation was run:
</p>
<code-block lang="Kotlin">
withService&lt;MyService&gt;() // ok
withService&lt;MyServiceImpl&gt;() // compile time ok, runtime throws
</code-block>
<p>
Our compiler plugin, however, can make this code behave as expected.
The compiler plugin enforces annotation type-safety by requiring type parameters to have specific annotations,
like <code>@Rpc</code>.
</p>
<code-block lang="Kotlin">
@Rpc
Expand All @@ -41,27 +42,27 @@
</code-block>

<note>
Annotation type safety only ensures that the resolved type parameters are annotated with the required annotation.
Annotation type safety only ensures that the resolved type parameters are annotated with the required
annotation.
The actual type of the passed argument may differ:
<code-block lang="Kotlin">
fun &lt;@Rpc T : Any&gt; registerService(body: () -> T) {}

// ok, T is resolved to MyService,
// but 'body' parameter returns MyServiceImpl
// T is resolved to MyService,
// but 'body' returns MyServiceImpl
registerService&lt;MyService&gt; { ctx -> MyServiceImpl(ctx) }

// error, T is resolved to MyServiceImpl
// Error: T is resolved to MyServiceImpl
registerService { ctx -> MyServiceImpl(ctx) }
</code-block>
</note>

<warning>
The feature is highly experimental.
The concept will stay, however due to the complexity of the implementation,
our compiler plugin may behave unexpectedly when performing type-safety checks.
Please, <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=bug_report.md">report</a> any encountered bugs.
This feature is highly experimental and may lead to unexpected behaviour. If you encounter any issues,
please <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=bug_report.md">report</a> them.

To ensure critical bugs don't paralyze your app, there is a kill-switch present for the feature:
To prevent critical bugs from affecting your app, you can disable this feature using the following
configuration:
<code-block lang="Kotlin">
// build.gradle.kts
rpc {
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/kotlinx-rpc/topics/configuration.topic
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
</title>

<warning>
These parameters are deprecated since <code>0.5.0</code>, see the <a href="0-5-0.topic">migration guide</a>.
These parameters are deprecated since <code>0.5.0</code>. For more information,
see the <a href="0-5-0.topic">migration guide</a>.
</warning>

<code-block lang="kotlin">
Expand Down
20 changes: 10 additions & 10 deletions docs/pages/kotlinx-rpc/topics/features.topic
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<p>
You can send and receive <a href="https://kotlinlang.org/docs/flow.html">Kotlin Flows</a> in RPC
methods.
This is only applied to <code>Flow</code> type, <code>StateFlow</code> and <code>SharedFlow</code>
are not supported and there are no plans to do so.
However, this only applies to the <code>Flow</code> type. <code>StateFlow</code> and <code>SharedFlow</code>
are not supported, and there are no plans to add support for them.
</p>

<code-block lang="kotlin">
Expand All @@ -32,7 +32,7 @@
</code-block>

<p>
Another limitation is that server-side steaming (flows that are returned from a function),
Another requirement is that server-side steaming (flows that are returned from a function),
must be the top-level type:
</p>

Expand All @@ -51,13 +51,13 @@
</code-block>

<note>
Note that flows that are declared in classes (like in <code>StreamResult</code>) require
Note that flows that are declared in classes (like in <code>StreamResult</code>) require a
<a href="https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#contextual-serialization">Contextual</a>
annotation.
</note>

<p>
To use flows in your code - you need to use special <code>streamScoped</code> function
To use flows in your code, use the <code>streamScoped</code> function
that will provide your flows with their lifetime:
</p>

Expand Down Expand Up @@ -85,17 +85,17 @@
After that, all streams that are still live will be closed.
</p>
<p>
You can have multiple RPC call and flows inside the <code>streamScoped</code> function, even from
You can have multiple RPC calls and flows inside the <code>streamScoped</code> function, including those from
different services.
</p>
<p>
On server side, you can use <code>invokeOnStreamScopeCompletion</code> handler inside your methods
to execute code after <code>streamScoped</code> on client side has closed.
On the server side, you can use the <code>invokeOnStreamScopeCompletion</code> handler inside your methods
to execute code after <code>streamScoped</code> on the client side has closed.
It might be useful to clean resources, for example.
</p>
<note>
<warning>
Note that this API is experimental and may be removed in future releases.
</note>
</warning>
<p>
Another way of managing streams is to do it manually.
For this, you can use the <code>StreamScope</code> constructor function together with
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/kotlinx-rpc/topics/service-descriptors.topic
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
This API is experimental and may be changed at any time.
</note>
<p>
Service Descriptors allow to access entities generated by the compiler plugin.
API can be accessed using the following code:
Service Descriptors allow you to access entities generated by the compiler plugin.
You can access them by using the following code:
</p>
<code-block lang="Kotlin">
serviceDescriptorOf&lt;MyService&gt;()
</code-block>
<p>
The list of available entities can be found <a href="https://github.com/Kotlin/kotlinx-rpc/blob/main/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt">in code</a>
For the list of available entities, refer to <a href="https://github.com/Kotlin/kotlinx-rpc/blob/main/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt">the source code</a>.
</p>
</topic>
10 changes: 5 additions & 5 deletions docs/pages/kotlinx-rpc/topics/strict-mode.topic
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
title="Strict mode" id="strict-mode">

<p>
Starting with version <code>0.5.0</code> library undergoes major change in supported service APIs.
Starting with version <code>0.5.0</code>, the library introduces major changes to the service APIs.
The following declarations will be gradually restricted:
</p>
<list>
<li>
<b>StateFlow and SharedFlow</b>
<b><code>StateFlow</code> and <code>SharedFlow</code></b>
<p>Deprecation level: <code>WARNING</code></p>
<code-block lang="kotlin">
@Rpc
Expand Down Expand Up @@ -66,7 +66,7 @@
</list>

<p>
Deprecation levels are controlled by the Gradle `rpc` extension:
Deprecation levels are controlled by the Gradle <code>rpc</code> extension:
</p>
<code-block lang="Kotlin">
// build.gradle.kts
Expand All @@ -88,9 +88,9 @@
Modes <code>RpcStrictMode.NONE</code> and <code>RpcStrictMode.ERROR</code> are available.
</p>

<note>
<warning>
Note that setting <code>RpcStrictMode.NONE</code> should not be done permanently.
All deprecated APIs will become errors in future without an option to suppress it.
Consider your migration path in advance.
</note>
</warning>
</topic>

0 comments on commit 5ce1f7d

Please sign in to comment.