# Creating an intentional delay in a loop inside a post-response script

**URL:** <https://community.postman.com/t/creating-an-intentional-delay-in-a-loop-inside-a-post-response-script/84592>\
**Category:** Help Hub\
**Tags:** scripts\
**Created:** [September 11, 2025, 4:38pm UTC](https://community.postman.com/t/creating-an-intentional-delay-in-a-loop-inside-a-post-response-script/84592 "2025-09-11T16:38:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geoangelmhdez](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@geoangelmhdez](https://community.postman.com/u/geoangelmhdez)\
**Post date:** [September 11, 2025, 4:38pm UTC](https://community.postman.com/t/creating-an-intentional-delay-in-a-loop-inside-a-post-response-script/84592/1 "2025-09-11T16:38:36Z")

</div>

I am checking the status of a previous request in a post-response script. Is there any way that I can I set some delay if the previous step has not finished yet and I want to wait, let’s say, 5 seconds? This delay is set inside a loop that after ten attempts will throw a timeout and stop.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 12, 2025, 10:50am UTC](https://community.postman.com/t/creating-an-intentional-delay-in-a-loop-inside-a-post-response-script/84592/2 "2025-09-12T10:50:49Z")

</div>

Yes, this is definitely doable—Postman runs on JavaScript behind the scenes, so you can use JavaScript features like `setTimeout`.

Instead of throwing an exception, a simpler approach is to create a variable at the top of your script (maybe call it `success`) and set it to `false` to start with.

Then, as your loop runs, if you get the expected status at any point, you can update that variable to `true`.

At the end of your script, you can add a proper test that checks the value of that variable. This will then show any failures in the tests results tab. If you’re running this as part of a collection and want to stop the whole thing when the condition is not met, you can use `postman.setNextRequest(null)` to halt further execution.

Quick question—how are you currently checking the status? Are you using `pm.sendRequest()` or looping with `setNextRequest()`?

If you can share your current code (feel free to redact any sensitive bits), I’ll be able to give you a more tailored example instead of just general advice.
