I want to save each element in the stream to it’s separate file. I’m not sure if I’m missing something or there is a bug, as for the last element the file is always created but it is empty.
val done =
Source(1 to 4)
.map(i => ByteString.fromString(i.toString))
.toMat(
LogRotatorSink.withSinkFactory(
triggerGeneratorCreator =
() => n => Some(Path.of(new String(s"file${n.decodeString("UTF-8")}" + ".txt"))),
sinkFactory =
(path: Path) =>
Flow[ByteString].toMat(FileIO.toPath(path, Set(CREATE, WRITE, TRUNCATE_EXISTING, SYNC)))(Keep.right)
)
)(Keep.right).run
Await.ready(done, 2.seconds)
system.terminate()
Await.ready(system.whenTerminated, 2.seconds)
1 post - 1 participant