1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以使用如下所示的代碼直接創(chuàng)建 Flux。請(qǐng)注意,我添加了一些假設(shè)的方法,您需要根據(jù)您的 SearchSupplier 的工作方式來(lái)實(shí)現(xiàn)這些方法:
Flux<SearchResultType> flux = Flux.generate(
() -> new SearchSupplier(this, queryBody),
(supplier, sink) -> {
SearchResultType current = supplier.next();
if (isNotLast(current)) {
sink.next(current);
} else {
sink.complete();
}
return supplier;
},
supplier -> anyCleanupOperations(supplier)
);
添加回答
舉報(bào)