# asLongAs condition problem

**URL:** <https://community.gatling.io/t/aslongas-condition-problem/2047>\
**Category:** Gatling (Open-Source)\
**Created:** [February 21, 2015, 10:05am UTC](https://community.gatling.io/t/aslongas-condition-problem/2047 "2015-02-21T10:05:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamie](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@Jamie](https://community.gatling.io/u/Jamie)\
**Post date:** [February 21, 2015, 10:05am UTC](https://community.gatling.io/t/aslongas-condition-problem/2047/1 "2015-02-21T10:05:16Z")

</div>

Hi,

I have defined a loop which is supposed to end once the current time is greater than a predefined value.

Before scenario:

val proposedEndTime = System.currentTimeMillis + (1_60_1000)

Inside scenario:

.asLongAs(proposedEndTime \> System.currentTimeMillis) {  
pause(1)  
.group(“ChatMessage”){  
exec(session =\> session.set(“sentOnTime”, System.currentTimeMillis))  
.exec(ws(“ActualChatMessage”).sendText("""{“messageType”: “newChatMessage”, “you”: “${currentUser}”, “thirdParty”: “${currentThirdParty}”,  
“sendTime”: “${sentOnTime}”, “message”: “Hello”}""")  
.check(wsAwait.within(10).until(1).regex("""{._“messageType”:“newChatMessage”,“you”:"${currentUser}",“thirdParty”:"${currentUser}",“message”:"",“wasSentOn”:"${sentOnTime}",“communicationWith”:"${currentThirdParty}"._}""")))  
}  
}

The problem is that the loop is never stopping, as if there is no condition. Do you have some ideas of what may be the problem?

Thanks a lot.

Jamie Tabone

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 22, 2015, 8:43am UTC](https://community.gatling.io/t/aslongas-condition-problem/2047/2 "2015-02-22T08:43:23Z")

</div>

First, your condition is not a function but is static, so it’s only evaluated once, when the simulation is built.  
You’d have to pass a function: .asLongAs(session =\> proposedEndTime \> System.currentTimeMillis)

Then, assuming what you want to achieve is indeed the sample you provided, using a during loop would be way more simple:  
during(60)

---

<div class="post-metadata">

**Author:** ![Jamie](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@Jamie](https://community.gatling.io/u/Jamie)\
**Post date:** [February 22, 2015, 11:06am UTC](https://community.gatling.io/t/aslongas-condition-problem/2047/3 "2015-02-22T11:06:09Z")

</div>

Thanks a lot 🙂 I solved it now.

Jamie Tabone
