Is it an anti-pattern to use async/await inside of a new Promise() constructor?

后端 未结 3 886
夕颜
夕颜 2020-11-22 00:28

I\'m using the async.eachLimit function to control the maximum number of operations at a time.

const { eachLimit } = require(\"async\");

functi         


        
3条回答
  •  心在旅途
    2020-11-22 01:08

    static getPosts(){
        return new Promise( (resolve, reject) =>{
            try {
                const res =  axios.get(url);
                const data = res.data;
                resolve(
                    data.map(post => ({
                        ...post,
                        createdAt: new Date(post.createdAt)
                    }))
                )
            } catch (err) {
                reject(err);                
            }
        })
    }
    

    remove await and async will solve this issue. because you have applied Promise object, that's enough.

提交回复
热议问题