File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/connection Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,15 @@ internal abstract class ConnectionEstablishmentHandler(
101101 }
102102 }
103103
104- override suspend fun RSocketConnection.initialize () = coroutineScope {
105- handleConnection(wrapConnection(this @initialize, coroutineContext.supervisorContext()))
104+ override suspend fun initialize (connection : RSocketConnection ) {
105+ try {
106+ coroutineScope {
107+ handleConnection(wrapConnection(connection, coroutineContext.supervisorContext()))
108+ }
109+ connection.cancel()
110+ } catch (cause: Throwable ) {
111+ connection.cancel(" Connection closed" , cause)
112+ throw cause
113+ }
106114 }
107115}
Original file line number Diff line number Diff line change @@ -21,13 +21,13 @@ import kotlinx.coroutines.*
2121
2222@RSocketTransportApi
2323internal interface RSocketConnectionInitializer <T > {
24- public suspend fun RSocketConnection. initialize (): T
24+ suspend fun initialize (connection : RSocketConnection ): T
2525}
2626
2727@RSocketTransportApi
2828internal suspend fun <T > RSocketConnectionInitializer<T>.runInitializer (connection : RSocketConnection ): T {
2929 val result = connection.async {
30- connection. initialize()
30+ initialize(connection )
3131 }
3232 try {
3333 result.join()
@@ -41,6 +41,6 @@ internal suspend fun <T> RSocketConnectionInitializer<T>.runInitializer(connecti
4141@RSocketTransportApi
4242internal fun RSocketConnectionInitializer<Unit>.launchInitializer (connection : RSocketConnection ): Job {
4343 return connection.launch {
44- connection. initialize()
44+ initialize(connection )
4545 }
4646}
You can’t perform that action at this time.
0 commit comments