Casey Brooks
10/15/2019, 7:26 PMreadLine()
in a while loop?trevjones
10/15/2019, 8:36 PMZach Klippenstein (he/him) [MOD]
10/15/2019, 8:58 PMval File.lines: Flow<String>
get() = flow<String> {
useLines { lines ->
emitAll(lines.asFlow())
}
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
octylFractal
10/15/2019, 9:32 PMreader.lineSequence().asFlow().onCompletion { reader.close() }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
Zach Klippenstein (he/him) [MOD]
10/15/2019, 9:43 PMuseLines
won’t close the source until the block exits, which won’t happen until the collector finishes processing the last line. If anything it will close the source too late, which I think is what your solution fixes.trevjones
10/15/2019, 9:45 PMasFlow().onCompletion
seems suspect to leak on anything but the happy path?octylFractal
10/15/2019, 9:50 PMonCompletion
is called upon exception as well iirctrevjones
10/15/2019, 9:50 PMoctylFractal
10/15/2019, 9:51 PMZach Klippenstein (he/him) [MOD]
10/16/2019, 6:19 PMemit
call suspends for a long time the file handle is effectively leaked. Could happen if a buffer(RENDEZVOUS)
was chained right after the flowOn
.