question on nested `use` blocks: let's say I have ...
# general-advice
j
question on nested
use
blocks: let's say I have a reader and a writer - if I nest the writer's
use
inside of the reader's
use
, and the reader is empty, will the writer's stream still be closed?
Copy code
val reader = reader()
val writer = writer()

reader.use {
  writer.use {
     reader.forEach {
        writer.write(it)
     }
  }
}
s
After the use lambda ends, why do you suspect it would not close the stream?
j
you are right, the outer
use
itself does not do any iteration, so we don't know to exit until we're inside the second
use
thanks for rubber ducking that 🙂
rubber duck 1
👍 1