Async Operations!

@singhsivcan It looks great! just had a question is there any drawbacks for below approaches when compared to this

Approach 1

pm.sendRequest("https://postman-echo.com/delay/6", (error, res) => {

    console.log(res)

    pm.sendRequest("https://postman-echo.com/delay/1", (error, res) => {

        console.log(res)

        pm.sendRequest("https://postman-echo.com/delay/2", (error, res) => {

            console.log(res)

        })

    })

})

Approach 2:


pm.environment.set("final", [])

let promisify = function (req) {

    return new Promise((resolve, reject) => {

        pm.sendRequest(req, (error, res) => {

            setTimeout(resolve(res), 1);

        })

    });

};

async function test() {

    await promisify("https://postman-echo.com/delay/3")

    await promisify("https://postman-echo.com/delay/1")

    await promisify("https://postman-echo.com/delay/2")

}

test()

//set time out to the max response time of the 3 requests

// here 3000 or 3 sec is the highest so we are keeping 5000

setTimeout(()=>{},5000)
4 Likes