What is a good strategy to convert coroutines from js to c#?

I have 30+ javascript files (I’m not the author) that I’ve already converted to C#; up until now I commented out the yield statements but now I’ll need to implement them. There are functions which have Yield statements that call other functions that have yield statements that call others, etc. Other times I have RPC functions calling functions that have yield.

My main problem I want to avoid is multiple calls to a function that has "StartCoroutine ( myfunction() ); in it.

Another problem I want to avoid is having callback functions like Update needing bool checks and dummy functions:

void Update()
{
function1();
function2();
function3(); // function 3 has a yield statement and must finish before function4()
function4();
}

I can create a dummy function like UpdateHandler() and use an isDone

bool isDone = true;
void Update()
{
if (isDone)
{
   isDone = false;
   StartCoroutine(UpdateHandler());
}
}
IEnumerator UpdateHandler()
{
function1();
function2();
yield return StartCoroutine(function3);
function4();
isDone = true;
}

If I do this I’ll have all these ugly handlers and isDone checks. Is this really necessary or is there a better solution?

Thanks!

Nope, you hit it on the head, it’s ugly but necessary if you are going past 1 frame. Though I would put the isDone = false in the coroutine. Makes it a little cleaner in the end.

or, how about this

IEnumerator someFn()
{
   StartCorutine(function3());
   while(!function3Done) //some var or something that would be set in fn3...
   //doesnt have to be a new var, so if fn3() sets a string, you can check to see if its valid before continuing
   {
      yield return 0;
   }

   //this wont happen until its done

   //heres an optional error check
   if(soemOtherVar == MyClass.FAILURE)
   {
      print(failed!)
      return 0;
   }
   //now do fn4 if everything is cool
   function4();
}

much cleaner and no need for a update method. you can add as many wait loops as you want, and within the loops, add time out counters, so you can exit the loops if they are taking to long (useful for www stuff)