Thanks guys. I think for now I will just keep the save function inside the loop for simplicity and only execute it every 1000 iterations. Channel wires might have worked as well.
You could also have a look at the Producer/Consumer, which uses a queue instead of a channel wire.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions Unofficial Forum Rules and Guidelines "Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5