```fun scroll() = flow { try { // do stuff ...
# coroutines
t
Copy code
fun scroll() = flow {
  try {
    // do stuff
  } finally {
    withContext(NonCancellable) { suspendingCleanUpFunction() }
  }
}
This does obviously not work. What would be the correct pattern here?
m
Why doesn't it work? Not too obvious to me 😛
t
Ah I am sorry. I had an
emit()
in some other place inside a
withContext(NonCancellable)
So is the above considered ok?
e
Yes. It is Ok. But you-might save some nesting by rewriting it like this:
Copy code
fun scroll = flow { /* doStuff */ }
    .onCompletion { /* do finally */ }