problem: CompoundReader makes unnecessary requests

This commit is contained in:
Igor Artamonov
2021-10-17 19:47:32 -04:00
parent e76e2bebf5
commit e37076936f
2 changed files with 34 additions and 20 deletions

View File

@@ -23,7 +23,8 @@ import reactor.core.publisher.Mono
import java.time.Duration
/**
* Composition of multiple readers. Reader returns first value returned by any of the source readers.
* Composition of multiple readers.
* Reader returns first value returned by any of the source readers by checking one by one until one of them returns a non-empty result.
*/
class CompoundReader<K, D>(
private vararg val readers: Reader<K, D>
@@ -38,12 +39,13 @@ class CompoundReader<K, D>(
return Mono.empty()
}
return Flux.fromIterable(readers.asIterable())
.flatMap { rdr ->
.flatMap({ rdr ->
rdr.read(key)
.timeout(Defaults.timeoutInternal, Mono.empty())
.doOnError { t -> log.warn("Failed to read from $rdr", t) }
.onErrorResume { Mono.empty() }
}.next()
}, 1)
.next()
}
}