Callback with Action from one script to another only works partially

Hello everyone,

I am using callback functions for the first time and I have a behaviour which I cannot explain. I hope you can help me.

My aim is to get a return value (a warning text from a firebase connection) from within an IEnumerator from another script.

UIManager Skript:

public void RegisterButton()
{
    string warningText = "";
    StartCoroutine(FirebaseManager.instance.Register(emailRegisterField.text, 
                                                    passwordRegisterField.text, 
                                                    passwordRegisterVerifyField.text, 
                                                    usernameRegisterField.text,
                                                    callbackWarningText => 
                                                    { 
                                                        warningText = callbackWarningText;
                                                        Debug.Log("INSIDE: " + warningText);
                                                    }));
    Debug.Log("OUTSIDE: " + warningText);
    warningRegisterText.text = warningText;
}

FirebaseManager Skript:

public IEnumerator Register(string _email, string _password, string _confirmPassword, string _username, System.Action<string> callbackWarningText)
    {
        if (_username == "")
        {
            //If the username field is blank show a warning
            callbackWarningText("Missing Username");
        }
        else if (_password != _confirmPassword)
        {
            //If the password does not match show a warning
            callbackWarningText("Password Does Not Match!");
        }
        else
        {
            //Call the Firebase auth signin function passing the email and password
            var RegisterTask = fbAuth.CreateUserWithEmailAndPasswordAsync(_email, _password);
            //Wait until the task completes
            yield return new WaitUntil(predicate: () => RegisterTask.IsCompleted);
        if (RegisterTask.Exception != null)
        {
            //If there are errors handle them
            Debug.LogWarning(message: $"Failed to register task with {RegisterTask.Exception}");
            FirebaseException firebaseEx = RegisterTask.Exception.GetBaseException() as FirebaseException;
            AuthError errorCode = (AuthError)firebaseEx.ErrorCode;

            string message = "Register Failed!";
            switch (errorCode)
            {
                case AuthError.MissingEmail:
                    message = "Missing Email";
                    break;
                case AuthError.MissingPassword:
                    message = "Missing Password";
                    break;
                case AuthError.WeakPassword:
                    message = "Weak Password";
                    break;
                case AuthError.EmailAlreadyInUse:
                    message = "Email Already In Use";
                    break;
            }
            callbackWarningText(message);
...

I mentioned that it works partially in the title since the first 2 checks (username + password) in the firebaseManager work as expected. If one of them is true I get the following debug output:

INSIDE: Missing Username
OUTSIDE: Missing Username

However, if something from within the switch statement triggers, the debug output is:

OUTSIDE:
INSIDE: Missing Email

So, I do not get a return value in these cases.

What got my attention is that in the latter case the OUTSIDE string is logged first. This could mean that the code within RegisterButton() continues before the warningText is set within the FirebaseManager, but why and why only do I have different behaviours?

Okay, I somehow solved the problem, but I would be really interested if anyone could explain me the difference!

I replaced the Lambda expression with a dedicated function (SetWarningText) and that’s it, now the warning text is always filled and not only sometimes?!

public void RegisterButton()
{
    StartCoroutine(FirebaseManager.instance.Register(emailRegisterField.text,
                                                    passwordRegisterField.text,
                                                    passwordRegisterVerifyField.text,
                                                    usernameRegisterField.text,
                                                    SetWarningText));
    ClearRegisterFields();
    ClearLoginFields();
}
private void SetWarningText(string returnValue)
{
    string warningText = returnValue;
    warningRegisterText.text = warningText;
}

Personal side note: Lambda expressions may be shorter, but they are much less easy to read. This is a good example in my opinion.