Looping Requests

Hey Guys,

Been making lots of head way, however i’m a bit stuck on a particular type of task. Which is looping through a result and making requests based on a previous request. I’m sure it’s something simple. Here’s how I would sort of expect it to work.

scenario(“Show Course”)
.feed(learners)
.exec(default)
// index modules stores a list of ids in the session
.exec(doIndexModules())
.exec(session => {
session(“moduleIds”).as[List[Int]].foreach(id => {
// some http task in here
exec(doSomeTaskWithModuleId(id));
})

session
})

This compiles, and executes, how ever the inner 'doSomeTaskWithModule does not. I’m obviously missing something, but my read and googling has yielded nothing.

Any guidance would be very helpful.

.joe

You can’t mix exec( session => session ) with exec( chain ). It’s got to be broken down into smaller, more fundamental steps.

In a exec( session => session ) function, extract the number of elements from moduleIds and store it, e.g. moduleIdCount

repeat( “${moduleIdCount}”, “n” ) {
exec( session => session.set( “moduleId”, “${moduleIds(n)}” ) )
exec( doSomeTaskWithModuleId ) // which must reference “${moduleId}” as opposed to taking a parameter
}

Make sense?

There may be a more elegant solution, but for that you will need someone more experienced than I. :slight_smile:

Yeah I think that’ll work for me.

Thanks a bunch :slight_smile: