Separate IO to a different thread

@oxmane Please CR
We should also close the writer here