有没有一种方法可以等待javascript异步功能完成,然后再继续

时间:2020-06-26 13:54:55

标签: javascript asynchronous async-await

我想在返回数据之前等待异步功能getPreprocessed运行,以使消息不会被不确定

data: result.rows.map(notification => {
            var message
            const entity_type_id = notification.entityTypeId
            const preProcess = entityTypeDetails[entity_type_id].process;

            async function getPreprocessed() {
                let processedData = []
                const promise = entityTypeDetails[entity_type_id].preProcessing
                for (let index = 0; index < promise.length; index++) {
                    const element = promise[index];
                    const processed = await element.process(notification)
                    processedData.push(processed)
                }
                processedData = Object.assign({}, ...processedData.map(object => (object)))
                message = res.__(entityTypeDetails[entity_type_id].messageProp,processedData)
            }
             getPreprocessed()
            
            return {
                    message: message,
                    notification_notifiers: notification.notification_notifiers[0]
                }
            })

0 个答案:

没有答案