The other observation is that using a channel with...
# coroutines
e
The other observation is that using a channel with UNLIMITED buffer has a potential for memory overflow when processing very large or continuous data sets. Here is the trick that lets you solve this. A typical “Visitor” pattern like the one you are using above does not have an explicit way to control back-pressure, but usually there is always an implicit way to do it. All the “visitXXX” methods are usually invoked from a single thread of execution and blocking in “visitXXX” usually provides this implicit back-pressure signal, slowing producer down. So, the trick is a limited-size channel with
send
instead of
offer
. But how do you invoke suspending
send
form non-suspending “visitXXX” funs? — use
runBlocking
.
🤔 1