I am currently writing a method which needs to add each element into a concurrentHashMap before continuing downstream. E.g.
public Flux<Bar> methodOne(final Flux<Foo> foos) {
Map<UUID, Foo> idToFoo = new ConcurrentHashMap<>();
return foos.doOnNext(foo -> idToFoo.put(foo.getId(), foo)
.flatMap(foo -> fooToBar(foo, idToFoo));
}
Can I be certain that within fooToBar()
that the passed map will be populated with the corresponding element?
From my understanding, doOnNext()
is synchronous and it execute and complete the lambda before continuing downstream. However, I am getting pushback from a senior dev – they think as this is a side-effect it is a ‘fire and forget’ type.
I am working on understanding the source code better so I can justify the use case but wanted to check here as well.
Thanks
Snuii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.