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 PMRicardo
12/03/2019, 6:36 PMemits
between try-catch
.catch
operator to catch any exception from the upstreamtry-catch
, you'll be risking funky behaviour like catching an exception thrown by an operator in the downstream, or even thrown by the terminal operatorfinally
and no catch
. You don't expect any exceptions?Luke Rohde
12/03/2019, 6:38 PMRicardo
12/03/2019, 6:39 PMonCompletion
operatorLuke 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-finally
Luke Rohde
12/03/2019, 6:42 PMRicardo
12/03/2019, 6:42 PMflow {
for (i in collection) {
emit(i)
doCleanupOn(i)
}
}
?Luke Rohde
12/03/2019, 6:44 PMRicardo
12/03/2019, 6:45 PMLuke Rohde
12/03/2019, 6:45 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 AM