I would assume this would work synchronously, based on an answer here.
My intention is to replace these console.log() statements with code which manages internal state of a modelled user (e.g., the total number of items bought in a demo shopping application), conditionally based on responses.
Hello! Yes, the code here runs synchronously, i.e. you should see 1->2->3->4 in your log output. The http.batch() call runs synchronously as well, i.e. it only returns once all of the requests in the batch have received a response (or have timed out).
Thanks, Tom! Building upon this, is there a nicer way to get variables from a group scope into its parent scope other than:
let var1;
group("visit type A", function () {
http.get(BASE_URL + "example.html");
const response = http.batch([
["GET", BASE_URL + "topbar.html"],
["GET", BASE_URL + "navbar.html"],
]);
var1 = response[0].status;
}
Is it okay to wrap the group in a promise (i.e., resolve(response[0].status))? Then I could chuck the wrapped group functions in an api.js/api.ts file and use async/await syntax.
Unfortunately, this is not possible at the moment, k6 doesn’t have event loops (and thus, async or promises) in yet. Instead, every VU is a completely separate and independent JS runtime. We also plan to introduce event loops and proper async support though, eventually… Follow https://github.com/loadimpact/k6/issues/882 for updates.