@@ -124,30 +124,25 @@ fun Application.main() {
124124 val queries = call.queries()
125125 val random = Random .Default
126126
127- val result = coroutineScope {
128- val worlds = selectWorlds(queries, random)
127+ val worlds = selectWorlds(queries, random)
129128
130- val worldsUpdated = buildList {
131- worlds.collect {
132- it.randomNumber = random.nextInt(DB_ROWS ) + 1
133- add(it)
134- }
135- }
129+ val worldsUpdated = buildList {
130+ worlds.collect { world ->
131+ world.randomNumber = random.nextInt(DB_ROWS ) + 1
132+ add(world)
136133
137- val updateRequests = worldsUpdated.map { world ->
138134 Mono .usingWhen(dbConnFactory.create(), { connection ->
139135 Mono .from(
140- connection.createStatement(UPDATE_QUERY ).bind(0 , world.randomNumber).bind(1 , world.id)
136+ connection.createStatement(UPDATE_QUERY )
137+ .bind(0 , world.randomNumber)
138+ .bind(1 , world.id)
141139 .execute()
142140 ).flatMap { Mono .from(it.rowsUpdated) }
143- }, Connection ::close)
141+ }, Connection ::close).awaitFirstOrNull()
144142 }
145-
146- Flux .merge(updateRequests).collectList().awaitFirst()
147- worldsUpdated
148143 }
149144
150- call.respondText(Json .encodeToString(result ), ContentType .Application .Json )
145+ call.respondText(Json .encodeToString(worldsUpdated ), ContentType .Application .Json )
151146 }
152147 }
153148}
@@ -182,7 +177,6 @@ private fun configurePostgresR2DBC(config: ApplicationConfig): ConnectionFactory
182177 val cp = ConnectionPoolConfiguration .builder(cf)
183178 .initialSize(config.property(" db.initPoolSize" ).getString().toInt())
184179 .maxSize(config.property(" db.maxPoolSize" ).getString().toInt())
185- // .maxLifeTime(Duration.ofMillis(Long.MAX_VALUE))
186180 .build()
187181
188182 return ConnectionPool (cp)
0 commit comments