0

i have this code. i'm looping through array and creating promise which contains multiple await functions. after all functions are finished i'm resolving for item and returning promise. but i'm getting error that TypeError: Chaining cycle detected for promise #<Promise>

const run = async () => {
    let res = await db.query(query);
    let items = res.rows;

    const promises = items.map((item, i) => {
        try {
            const one = new Promise(async (resolve, reject) => {
                const product = await stripe.products.create(...);
                const session = await stripe.checkout.sessions.create(...);
                const price = await stripe.prices.create(...);

                await saveInvoice(...);
                let user = await someF(...);
                await someF2(..,..,..,);
                resolve(item);
            });
            return one;

        } catch (error) {
            console.log(error);
            process.exit();
        }
    });
    await Promise.all(promises).then(() => {
        process.exit();
    });
}
run(); 
Gia Nebieridze
  • 141
  • 3
  • 14
  • 2
    FYI: [Is it an anti-pattern to use async/await inside of a new Promise() constructor?](https://stackoverflow.com/q/43036229) – VLAZ Apr 27 '23 at 08:16
  • 2
    I don't think the code you've shown is the one responsible for the chaining cycle – Bergi Apr 27 '23 at 11:18

0 Answers0