Luke Rohde
12/03/2019, 6:25 PMflow {
for (i in collection) {
try {
emit(i)
} finally {
doCleanupOn(i)
}
}
}
is there a better way to accomplish this?octylFractal
12/03/2019, 6:34 PMLuke Rohde
12/03/2019, 6:35 PMLuke Rohde
12/03/2019, 6:36 PMRicardo
12/03/2019, 6:36 PMemits between try-catchRicardo
12/03/2019, 6:36 PM.catch operator to catch any exception from the upstreamRicardo
12/03/2019, 6:37 PMtry-catch , you'll be risking funky behaviour like catching an exception thrown by an operator in the downstream, or even thrown by the terminal operatorRicardo
12/03/2019, 6:38 PMfinally and no catch. You don't expect any exceptions?Luke Rohde
12/03/2019, 6:38 PMLuke Rohde
12/03/2019, 6:38 PMRicardo
12/03/2019, 6:39 PMonCompletion operatorRicardo
12/03/2019, 6:39 PMLuke Rohde
12/03/2019, 6:40 PMLuke Rohde
12/03/2019, 6:40 PMLuke Rohde
12/03/2019, 6:40 PMRicardo
12/03/2019, 6:42 PMonCompletion does the same as having your flow's collection inside a try-finallyLuke Rohde
12/03/2019, 6:42 PMRicardo
12/03/2019, 6:42 PMRicardo
12/03/2019, 6:43 PMRicardo
12/03/2019, 6:44 PMflow {
for (i in collection) {
emit(i)
doCleanupOn(i)
}
}
?Luke Rohde
12/03/2019, 6:44 PMLuke Rohde
12/03/2019, 6:44 PMRicardo
12/03/2019, 6:45 PMLuke Rohde
12/03/2019, 6:45 PMLuke Rohde
12/03/2019, 6:47 PMRicardo
12/03/2019, 6:55 PMcodeslubber
12/03/2019, 9:28 PMoctylFractal
12/03/2019, 9:31 PMemit(i) and then immediately call doCleanupOn(i) is very sequential-like, so this seems to be an example of coroutines working well towards their goalcodeslubber
12/03/2019, 9:34 PMoctylFractal
12/03/2019, 9:47 PMemit(i), and in emit, the downstream uses the element, processes it, etc. So clearly exceptions from downstream are thrown from emit.
catch 's implementation uses collect & emit, collect throws the errors from upstream generation and the emit calls, and special handling around emit figures out if exceptions thrown from collect are from up or downstream. It's not very complicated at all.codeslubber
12/03/2019, 9:57 PMDico
12/04/2019, 7:04 AMemit returns does not apply to some flow operators, namely buffering ones.
But it might work in your use case.Luke Rohde
12/04/2019, 3:33 PMDico
12/05/2019, 3:11 AMursus
12/05/2019, 7:16 AMursus
12/05/2019, 7:17 AM