@@ -17,16 +17,16 @@ import kotlin.coroutines.coroutineContext
1717internal val logger = InlineLogger ()
1818
1919/* *
20- * Calls the specified suspending [block] in the context of a [CoroutineConnection], suspends until it completes, and
21- * returns the result.
20+ * Calls the specified suspending [block] [with the context][withContext] of a [CoroutineConnection], suspends until it
21+ * completes, and returns the result.
2222 *
23- * When the [coroutineContext] has an [open connection ][hasOpenConnection] the [block] will be immediately invoked
24- * within that context.
23+ * When the [coroutineContext] has an [open][hasOpenConnection] [Connection ] the [block] will be immediately invoked
24+ * [with that context][withContext] .
2525 *
26- * When the [coroutineContext] has no [Connection], or it [is closed][isClosedCatching], the [block] will be invoked in
27- * the context of a new [Connection]. The new [Connection] will be created by the [DataSource] in the
28- * [coroutineContext], throwing an [IllegalStateException] if no such [DataSource] exists. After the [block] is invoked,
29- * the newly established [Connection] will be [closed][closeCatching].
26+ * When the [coroutineContext] has no [Connection], or it [is closed][isClosedCatching], the [block] will be invoked
27+ * [with the context][withContext] of a new [Connection]. The new [Connection] is established by the [DataSource] in the
28+ * [coroutineContext], throwing an [IllegalStateException] if no [DataSource] is present within the context. After the
29+ * [block] is invoked, the newly established [Connection] will be [closed][closeCatching].
3030 */
3131suspend inline fun <T > withConnection (crossinline block : suspend CoroutineScope .() -> T ): T {
3232 contract {
@@ -38,13 +38,13 @@ suspend inline fun <T> withConnection(crossinline block: suspend CoroutineScope.
3838 block()
3939 }
4040 } else {
41- val newConnection = coroutineContext.dataSource.connection
41+ val connection = coroutineContext.dataSource.connection
4242
43- withContext(CoroutineConnection (newConnection )) {
43+ withContext(CoroutineConnection (connection )) {
4444 try {
4545 block()
4646 } finally {
47- newConnection .closeCatching()
47+ connection .closeCatching()
4848 }
4949 }
5050 }
0 commit comments