Start a goroutine and use channels to communicate and coordinate reading/writing. Use defer in the goroutine.