Kotlin / kotlinx-rpc

Add asynchronous RPC services to your multiplatform applications.
https://kotlin.github.io/kotlinx-rpc/
Apache License 2.0
533 stars 7 forks source link

Stream Scopes #49

Closed Mr3zee closed 2 months ago

Mr3zee commented 2 months ago

Problem Description Previous version of kRPC did very little on stream lifetime handling. It was impossible to ensure, that your application doesn't have any leaks.

Solution Solution is to introduce two new functions: streamScoped and invokeOnStreamScopeCompletion. First one creates a "Stream scope" inside which new RPC streams may be created. And when scope is finished - all streams are cancelled. invokeOnStreamScopeCompletion provides a hook to subscribe to a steam scope closure.

PR is divided into main 3 parts (by commits):