-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated RpcClient and kRPC to new descriptor API
- Loading branch information
Showing
18 changed files
with
242 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.rpc | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.rpc.descriptor.RpcServiceDescriptor | ||
import kotlinx.rpc.internal.FieldDataObject | ||
import kotlinx.rpc.internal.RpcFlow | ||
|
||
/** | ||
* Registers Flow<T> field of the interface. Sends initialization request, subscribes to emitted values | ||
* and returns the instance of the flow to be consumed | ||
* | ||
* @param T type parameter for Flow | ||
* @param serviceScope Service's coroutine scope | ||
* @param fieldName the name of the field. | ||
* @param descriptor descriptor of the service, that made the call | ||
* that is used to be mapped to the corresponding field on a server. | ||
* @param serviceId id of the service, that made the call | ||
* @return Flow instance to be consumed. | ||
*/ | ||
public fun <T> RpcClient.registerPlainFlowField( | ||
serviceScope: CoroutineScope, | ||
fieldName: String, | ||
descriptor: RpcServiceDescriptor<*>, | ||
serviceId: Long, | ||
): Flow<T> { | ||
return RpcFlow.Plain(descriptor.fqName, initializeFlowField(serviceScope, fieldName, descriptor, serviceId)) | ||
} | ||
|
||
/** | ||
* Registers SharedFlow<T> field of the interface. Sends initialization request, subscribes to emitted values | ||
* and returns the instance of the flow to be consumed | ||
* | ||
* @param T type parameter for SharedFlow | ||
* @param serviceScope Service's coroutine scope | ||
* @param fieldName the name of the field. | ||
* @param descriptor descriptor of the service, that made the call | ||
* that is used to be mapped to the corresponding field on a server. | ||
* @param serviceId id of the service, that made the call | ||
* @return SharedFlow instance to be consumed. | ||
*/ | ||
public fun <T> RpcClient.registerSharedFlowField( | ||
serviceScope: CoroutineScope, | ||
fieldName: String, | ||
descriptor: RpcServiceDescriptor<*>, | ||
serviceId: Long, | ||
): SharedFlow<T> { | ||
return RpcFlow.Shared(descriptor.fqName, initializeFlowField(serviceScope, fieldName, descriptor, serviceId)) | ||
} | ||
|
||
/** | ||
* Registers StateFlow<T> field of the interface. Sends initialization request, subscribes to emitted values | ||
* and returns the instance of the flow to be consumed | ||
* | ||
* @param T type parameter for StateFlow | ||
* @param serviceScope Service's coroutine scope | ||
* @param fieldName the name of the field. | ||
* @param descriptor descriptor of the service, that made the call | ||
* that is used to be mapped to the corresponding field on a server. | ||
* @param serviceId id of the service, that made the call | ||
* @return StateFlow instance to be consumed. | ||
*/ | ||
public fun <T> RpcClient.registerStateFlowField( | ||
serviceScope: CoroutineScope, | ||
fieldName: String, | ||
descriptor: RpcServiceDescriptor<*>, | ||
serviceId: Long, | ||
): StateFlow<T> { | ||
return RpcFlow.State(descriptor.fqName, initializeFlowField(serviceScope, fieldName, descriptor, serviceId)) | ||
} | ||
|
||
private fun <T, FlowT : Flow<T>> RpcClient.initializeFlowField( | ||
serviceScope: CoroutineScope, | ||
fieldName: String, | ||
descriptor: RpcServiceDescriptor<*>, | ||
serviceId: Long, | ||
): Deferred<FlowT> { | ||
return callSync(serviceScope, RpcCall(descriptor, fieldName, FieldDataObject, serviceId)) | ||
} |
Oops, something went wrong.