Waiting multiple LoadContentCatalogAsync

Hi guys.
I have multiple project that build addressable bundles for my main project, each of them will generate unique CatalogContent file.
In my main project I need to load all of the input content catalogs and will have callback for when this process is done, error (Exception handling)
How do I do it, I tried to use naive way like this

    IEnumerator DownloadAllContentCatalog(JArray catalogs, Action onSuccess, Action onFail)
    {
        List<Task<IResourceLocator>> tasks = new List<Task<IResourceLocator>>();
        for (int i = 0; i < catalogs.Count; i++)
        {
            string catalogPath = AddressablesRuntimeManager.RunTimeLoadPath + "/" + catalogs[i].Value<string>() + "/catalog_" + catalogs[i].Value<string>() + ".json";
            var downloadTask = Addressables.LoadContentCatalogAsync(catalogPath, true).Task;
            tasks.Add(downloadTask);
        }
        var task = Task.WhenAll(tasks);
        while (!task.IsCompleted)
        {
            yield return new WaitForEndOfFrame();
        }
        if (task.Status == TaskStatus.RanToCompletion)
        {
            Debug.Log("Finish download all catalogs");
            onSuccess?.Invoke();
        }
        else
        {
            Debug.Log("Fail download catalogs");
            onFail?.Invoke();
        }
    }

But when I’m passing to wrong value to check for exception it’ll just go to Finish download all catalogs.
I’m fairly new to async handling so if I do something wrong please let me know

You are checking if tasks are completed which is always true in your case. Even with wrong catalog path your code will proceed to if statement with successful task completion because downloadTask receives null values and then those values are added to list. Everything seems fine, tasks are completed but actual catalogs are not loaded in your game.
Don’t use task on LoadContentCatalogAsync method, use AsyncOperationHandle
For example:

AsyncOperationHandle<IResource> handle  = Addressables.LoadContentCatalogAsync(catalogPath, true)

if(handle.Status == AsyncOperationStatus.Succeded)
{
...
}

you can also use event handler on handle object when loading is completed and subscribe with method you want.

handle.Completed += SomeMethod

Check what else is provided on handle : Struct AsyncOperationHandle | Addressables | 1.19.19

You can use task on handle and do whatever async logic you want but make sure you call load catalog method on that handle. That way if your catalog path is not correct, you will get exceptions which could be caught with try catch block. You could also check for correct catalog path or do you actually have catalogs in that path before you even start DownloadAllContentCatalog method.

Hi
Sorry for my late reply
I’ve create a workaround for my use case using Coroutine and it turn out great

        IEnumerator InternalLoadAllCatalog(ResultDelegate onResult)
        {
            List<AsyncOperationHandle<IResourceLocator>> handles = new List<AsyncOperationHandle<IResourceLocator>>();
            List<string> catalogs = addressableData.GetGameCatalog();
            for (int i = 0; i < catalogs.Count; i++)
            {
                string catalogPath = catalogs[i];
                var handle = Addressables.LoadContentCatalogAsync(RunTimeLoadPath + "/" + catalogPath);
                handles.Add(handle);
            }
            while (handles.Any(h => !h.IsDone))
            {
                yield return frameWait;
            }
            if (handles.All(h => h.Status == AsyncOperationStatus.Succeeded))
            {
                Debug.Log("Finish download all catalogs");
                onResult?.Invoke(true);
            }
            else
            {
                Debug.Log("Fail download catalogs");
                onResult?.Invoke(false);
            }
            handles.ForEach(h => Addressables.Release(h));
        }

Only that I have now on some time when I newly installed application, it’s load all content catalog but cannot down them immediately, even the download size return 0 (Work on editor tho). I have to reset the application to download the content in that content catalog