implementation for stream serialization using coroutine