replace polling logic with process.wait()