generator: Rewrite to use coroutine module