# Executing sync requests programmatically from a pre-request or test scripts

**URL:** <https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678>\
**Category:** Help Hub\
**Tags:** sync, scripts, pmsendrequest, pm, tests\
**Created:** [August 3, 2020, 2:16pm UTC](https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678 "2020-08-03T14:16:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [August 3, 2020, 7:41pm UTC](https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678/2 "2020-08-03T19:41:12Z")

</div>

Hi @tmladenov_atos,

Is this just about control flow aesthetics and avoiding “callback hell”?

If so, you _can_ use async/await style JavaScript syntax in the Postman Sandbox. It just requires a little hack. The Postman Sandbox detects open timeouts and intervals and awaits execution until they’re all cleared/resolved. If we use a dummy `Interval` object, we can use async/await to have a cleaner method of chaining asynchronous calls.

Example:

```auto
const _dummy = setInterval(() => {}, 300000);

function sendRequest(req) {
    return new Promise((resolve, reject) => {
        pm.sendRequest(req, (err, res) => {
            if (err) {
                return reject(err);
            }

            return resolve(res);
        })
    });
}

(async function main() {
    const result1 = await sendRequest('http://postman-echo.com/get');
    console.log('result1:', result1.code);

    const result2 = await sendRequest('http://postman-echo.com/get');
    console.log('result2:', result2.code);

    const result3 = await sendRequest('http://postman-echo.com/get');
    console.log('result3:', result3.code);

    clearInterval(_dummy)
})();

```

Hope this helps.

Best,

Kevin

---

_[View the full topic](https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678)._
