0
\$\begingroup\$

I just came across a coroutine in my project, which does few calculation, which could have been done using normal function.There is no loop in that coroutine and contains yield return null; in the last line. Is there any specific reason to use coroutine rather than normal function?

void Init(){
RenderObject();

}


IEnumerator Init(){
RenderObject();
yield return null;
}

EDIT:

Inside the RenderObject function, they are calling another coroutine which has two yield instructions yield return true; and yield return new WaitUntil(() => based on certain condition, calling to server takes place primarily.

\$\endgroup\$
  • \$\begingroup\$ In this case - no. \$\endgroup\$ – joltmode Jun 15 '17 at 12:01
  • 1
    \$\begingroup\$ I can't find any case where this has a useful outcome. Can you maybe show more context around how it's used, just in case we're overlooking something? At this point, my best bet is that the method used to need to do something the frame after RenderObject(), but that got refactored out, leaving the bottom part of the method empty. Or the developer was anticipating they'd need a longer-running multi-frame coroutine here in future, so they stubbed in the method as a coroutine and added a yield somewhere harmless (if puzzling) so the compiler wouldn't generate an error. \$\endgroup\$ – DMGregory Jun 15 '17 at 12:24
  • \$\begingroup\$ @DMGregory Inside the function, they are calling another coroutine which has two yield instructions yield return true; and yield return new WaitUntil(() => based on certain condition, calling to server takes place primarily. \$\endgroup\$ – MrRobot9 Jun 15 '17 at 13:07
  • 2
    \$\begingroup\$ To add more detail to your question, please use the edit button. That way all the information is in one place, and folks don't have to follow a whole comment threat to piece-together the situation. You also get better tools for code formatting that way. :) \$\endgroup\$ – DMGregory Jun 15 '17 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.