Javascript:循环中的所有promise都无法解决,这会使执行挂起/停止

我有一个特殊的情况,即我遍历多个工件并基于一组规则(在JSON中),我必须评估它们中的每一个,因为检查每个规则的调用是异步的,我已经使用了promise.all在评估完所有规则之后,请执行一些最后步骤。

以下代码用于根据一个工件的规则类型评估规则。

Const promises=[];    
var ruleTest = function (artifact) {
        main.totalLength++;
        var config = RuleEngine.RuleConfigurations;
        // fetching rules and iterating through each of them to call has_attribute function or contains function based on the Type in the JSON config
        for (let i = 0; i < config.length; i++) {
            console.log(config[i]);

            switch (config[i].Rule.Type) {
                case "has_Attribute":
                    has_Attribute(artifact, config[i]);
                    break;
                case "contains":
                    contains(artifact, config[i]);
                    break;
            }
        }

        Promise.all(promises).then(values => {
            console.log(values);
            console.log(main.contentList)
            // some final steps after all the promise are resolved
            main.loading = false;
            main.displayInfo = true;
            main.showInfo = true;
            //issuesFlag=false;
        })

}

function has_Attribute(artifact, rule) {
    var attributes = rule.Rule.MandatoryAttributes.split(',');
    for (let i = 0; i < attributes.length; i++) {
        attributes[i] = attributes[i].trim();
    }

        promises.push(hasAttributePromise(artifact, rule, attributes));
}

var hasAttributePromise = function (artifact, rule, attributes) {
    return new Promise((resolve, reject) => {
        // some async stuff
        resolve(value);
        }
    }

function contains(artifact, rule) {
    //some business logic
    promises.push(containsPromise(artifact, rule, blackListWords, whiteListWords))
}

var containsPromise = function (artifact, rule, blackListWords, whiteListWords) {
    return new Promise((resolve) => {
        //some async stuff
        resolve(value);
    }
}

我面临的问题是即使有两个规则(每种类型中的一个),即使在调用第二个promise之前脚本就已退出,并且页面似乎因为promise.all而卡住了。我必须针对多个规则实施此操作,并且基于规则类型将多次创建相同的承诺。

奇怪的是,如果我使用变量名创建诺言而不是从函数中返回它,而我在诺言中用变量名调用它,那么每次调用它都会工作一次,然后退出。 例如:

    var ruleTest = function (artifact) {
    main.totalLength++;
    RuleEngine.RuleConfigurations.forEach(function (rule) {
        console.log(rule)
        switch (rule.Rule.Type) {
            case "has_Attribute":
                has_Attribute(artifact, rule);
                break;
            case "contains":
                contains(artifact, rule);
                break;
        }
    })

    Promise.all([hasAttributePromise, containsPromise]).then(values => {
        console.log(values);
        console.log(main.contentList)
        if (issuesFlag){
            main.updatedLength++;
        }
        main.loading = false;
        main.displayInfo = true;
        main.showInfo = true;
        issuesFlag=false;
    })
}

  function has_Attribute(artifact, rule) {
    var attributes = rule.Rule.MandatoryAttributes.split(',');
    for(var i=0; i<attributes.length; i++){
        attributes[i]=attributes[i].trim();
    }

    hasAttributePromise = new Promise((resolve, reject) => {
        asyncCall(()=>{
            //business logic
            resolve();
        })
    });
}

我也尝试过使用forEach而不是for循环,但这无济于事。

我对Java语言非常陌生,无法指出问题所在,因此即使这是一个愚蠢的错误,也请在这里帮助我。