I am trying to save a set of categories. When all categories are saved, set the categories of product to it. Then return Product. So far I've managed to do this.
public Mono<Product> save(Product product) {
final Set<Category> categories = product.getCategories();
Set<Category> _categorySet = new HashSet<>();
Mono<Product> _product;
for (Category category : categories) {
final Mono<Category> save = categoryService.save(category);
save.subscribe(_categorySet::add,null,()->{
product.setCategories(_categorySet);
repository.save(product);
});
}
}
How do I return product after it has been saved without relying on block()
? I cannot seem to find a source to learn these stuffs. Can someone point me to good materials.