CavalliumDBEngine/src/main/java/it/cavallium/dbengine/client/SearchResult.java

22 lines
624 B
Java
Raw Normal View History

2021-02-03 20:13:17 +01:00
package it.cavallium.dbengine.client;
2021-08-04 01:12:39 +02:00
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
2021-02-03 20:13:17 +01:00
import reactor.core.publisher.Flux;
2021-07-10 20:52:01 +02:00
import reactor.core.publisher.Mono;
2021-02-03 20:13:17 +01:00
2021-08-04 01:12:39 +02:00
public record SearchResult<T, U>(Flux<SearchResultItem<T, U>> results, TotalHitsCount totalHitsCount, Mono<Void> release) {
2021-02-03 20:13:17 +01:00
public static <T, U> SearchResult<T, U> empty() {
2021-08-04 01:12:39 +02:00
return new SearchResult<>(Flux.empty(), TotalHitsCount.of(0, true), Mono.empty());
2021-07-10 20:52:01 +02:00
}
public Flux<SearchResultItem<T, U>> resultsThenRelease() {
return Flux
.usingWhen(
Mono.just(true),
_unused -> results,
_unused -> release
);
2021-02-03 20:13:17 +01:00
}
}