How to receive response using pm.sendRequest in a loop synchronously

Hello. I need to update one resource multiple times, but each update requires new token. So I need send 2 requests each loop and receive responses in exact order. Trying to use callback something like here:

for (let number of list) {
const Request1 = {
any valid request 1
};
const Request2 = {
any valid request 2
};

if (list !== null && number !== 1) {
   
    pm.sendRequest (Request1, function (err, res) {
        if (err) {console.log(err);}
        
        if (pm.expect(res).to.have.property('code', 200)) {
            const responce = res.json();
            const newToken = response.elearningSessionId;
            pm.environment.set("newToken", newToken);

            pm.sendRequest (Request2, function (err, res) {
            if (err) {console.log(err);}
                pm.expect(res).to.have.property('code', 200)
    });
    });
};

};

But itโ€™s still works randomly (not Loop1: Request1 -> Request2 Loop2: Request1 -> Request2. It works like Loop1:Request1, Loop2:Request1 and then both Requests 2). Code is just example, not working one.

Thanks in advance.

Hi,
I believe you use the wrong scope. If you store in the environment, there might be problems with overlap. You should IMHO use the local scope (https://learning.postman.com/docs/sending-requests/variables/).
Then the fact that Loop1 and Loop2 overlap shouldnโ€™t impact.
Naturally, if you have a 3rd request in the collection that needs to use the same token that might still be problematic.
Bernard