@@ -124,30 +124,25 @@ fun Application.main() {
124
124
val queries = call.queries()
125
125
val random = Random .Default
126
126
127
- val result = coroutineScope {
128
- val worlds = selectWorlds(queries, random)
127
+ val worlds = selectWorlds(queries, random)
129
128
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)
136
133
137
- val updateRequests = worldsUpdated.map { world ->
138
134
Mono .usingWhen(dbConnFactory.create(), { connection ->
139
135
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)
141
139
.execute()
142
140
).flatMap { Mono .from(it.rowsUpdated) }
143
- }, Connection ::close)
141
+ }, Connection ::close).awaitFirstOrNull()
144
142
}
145
-
146
- Flux .merge(updateRequests).collectList().awaitFirst()
147
- worldsUpdated
148
143
}
149
144
150
- call.respondText(Json .encodeToString(result ), ContentType .Application .Json )
145
+ call.respondText(Json .encodeToString(worldsUpdated ), ContentType .Application .Json )
151
146
}
152
147
}
153
148
}
@@ -182,7 +177,6 @@ private fun configurePostgresR2DBC(config: ApplicationConfig): ConnectionFactory
182
177
val cp = ConnectionPoolConfiguration .builder(cf)
183
178
.initialSize(config.property(" db.initPoolSize" ).getString().toInt())
184
179
.maxSize(config.property(" db.maxPoolSize" ).getString().toInt())
185
- // .maxLifeTime(Duration.ofMillis(Long.MAX_VALUE))
186
180
.build()
187
181
188
182
return ConnectionPool (cp)
0 commit comments