# alternatives to pause()

**URL:** <https://community.gatling.io/t/alternatives-to-pause/3061>\
**Category:** Gatling (Open-Source)\
**Created:** [June 9, 2016, 12:37pm UTC](https://community.gatling.io/t/alternatives-to-pause/3061 "2016-06-09T12:37:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_Hansen](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kenneth\_Hansen](https://community.gatling.io/u/Kenneth_Hansen)\
**Post date:** [June 9, 2016, 12:37pm UTC](https://community.gatling.io/t/alternatives-to-pause/3061/1 "2016-06-09T12:37:18Z")

</div>

Due to the nature of our system, we end up doing a lot of pause() in our tests.

Are there any alternatives to wait a fixed time? Like e.g. Spock’s PollingConditions? ([http://spockframework.github.io/spock/javadoc/1.0/spock/util/concurrent/PollingConditions.html](http://spockframework.github.io/spock/javadoc/1.0/spock/util/concurrent/PollingConditions.html))

---

<div class="post-metadata">

**Author:** ![Alexander\_Weiss](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Alexander\_Weiss](https://community.gatling.io/u/Alexander_Weiss)\
**Post date:** [June 9, 2016, 1:04pm UTC](https://community.gatling.io/t/alternatives-to-pause/3061/2 "2016-06-09T13:04:02Z")

</div>

I think you should provide a bit more information to get a proper advice.

Anyways, I wrote a method for one of my loadtests that keeps polling a server until the response contains a given regex (and therefore blocks the scenario execution)  
Maybe this is a possible solution for you:

`

/\*\*

- Polls for a given RegExp and saves the result in the session as .  
\*/  
def poll(stepName: String, regExpression: String, saveString: String, intervalMillis: Int, maxTries: Int): ChainBuilder = {

return exec(session =\> {  
session.set(“pollingCounter”, 0)  
session.set(“maxTries”, maxTries - 1)  
})

//Try with optional polls → Won’t fail the run  
.asLongAs(session =\> {  
session.get(“pollingCounter”).as[Int] \< session.get(“maxTries”).as[Int] && !session.contains(saveString)  
}) {  
exec(http(stepName).get(\<POLLING\_STRING\>)  
.check(regex(session =\> {  
session.set(“pollingCounter”, session.get(“pollingCounter”).as[Int] + 1)

regExpression  
}).optional.saveAs(saveString),  
.pause(intervalMillis milliseconds)  
}  
//Final non-optional poll that fails the current run if it isn’t successful.  
.doIf(session =\> {  
session.get(“pollingCounter”).as[Int] \>= session.get(“maxTries”).as[Int]  
})(exec(http(stepName).get(\<POLLING\_STRING\>)  
.check(  
regex(regExpression).saveAs(saveString),  
.exitHereIfFailed)  
}

`
