Search Unity

How to improve Corountine

Discussion in 'Scripting' started by SplashFoxGames, Jun 18, 2019.

  1. SplashFoxGames

    SplashFoxGames

    Joined:
    Oct 10, 2012
    Posts:
    53
    I have lot of RestAPI calls. I am not sure that the corountine is the best choise for that. What can you advice? It takes like 500 ms - 1 second for full process even with a small data.

    Code (CSharp):
    1.         private IEnumerator SendRequest(UnityWebRequest webRequest, System.Action<string> onSuccess, System.Action<long, string> onError)
    2.         {
    3.             yield return webRequest.SendWebRequest();
    4.  
    5.             HandleResponse(webRequest, onSuccess, onError);
    6.         }
     
  2. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    Are you making all of the calls at the same time, or only a few at a time? If you are making many many requests at the same time, you might need to redesign your approach to make fewer requests. If you have control over the target you are making the request to, you could try having a batch request, where you give the target a large amount of small things to do in a single request.
    If instead you only make a few requests at a time, then the problem is with your network, or the target. Web requests are a little slow depending on the server you are targeting, but it shouldn't be that slow for most countries.