How to wait first post issue and use while loop in k6 load test scripts?

I have two post request.This post request should run until the response is “createdIsCompleted” == false .I m taking createdIsCompleted response from second post isssue. So how can I run two requests in while loop. By the way, I have to wait first post issue before the second post issue should be run…I know there is no await operator in k6. But I want to learn alternative ways. This while loop not working as I want. The response still returns “createdIsCompleted” == true

let createdISCompleted;
 describe('place products', (t) => {
            while (createdIsCompleted == false) {
              

               http.post(requestUrlAPI + 'PickingProcess.checkCell', JSON.stringify({
                    cellLabel: `${createdCellLabel}`,
                    pickingReferenceNumber: `${createdpickingProcessReferenceNumber}`,
                    allocatedItemId: `${createdAllocatedItemId}`,
                }), generateTokenHeader)

                let placeProductRes = http.post(requestUrlAPI + 'PickingProcess.placeProduct', JSON.stringify({
                    cellLabel: `${createdCellLabel}`,
                    pickingReferenceNumber: `${createdpickingProcessReferenceNumber}`,
                    pickingToteLabel: `${createdPickingToteLabel}`,
                    productLabel: `${createdProductLabel}`,
                    allocatedItemId: `${createdAllocatedItemId}`,
                }), generateTokenHeader) 
                createdIsCompleted = placeProductRes.json().isCompleted;
               
                break;
            }
        });

Hi, @Yusuf ,

By the way, I have to wait first post issue before the second post issue should be run

This what is happening - k6 blocks on the http.post until it finishes and then continues with the next request. You don’t need to do anything.

his while loop not working as I want. The response still returns “createdIsCompleted” == true

Looking at the break; at the end this while loop will loop once. What happens if you remove it ? You can insert some console.log statements to log the response on each iteration so you can be certain someething is happening. At least while developing it.

Hi @mstoykov

Thanks for good information. But when I add console.log in while loop there is no information related to console.log. Can it be because of while loop?

I guess you just never enter the loop as createdIsCompleted is actually undefined. So if you set it to false initially it should work.

Also of note is that one of them is with small s the other not in is
createdISCompleted
createdIsCompleted