Periodically refreshing a token aside a script

Hi @camillegr,
welcome to the community forum :tada:

If you can use a dedicated token per VU then you can check the time elapsed from the last refresh and execute a new one after 5 seconds.

var refreshed = 0;

export default function() {
	var diff = new Date() - refreshed 
	if (diff > 4999) {
		console.log(`refresh the token`)
		refreshed = new Date()
	}
}

Even better if you create an HTTP wrapper where this logic is executed before each request so the code will be cleaner.

When the PR for #882 will be merged then a setTimeout could be a valid alternative. You can subscribe to it to know when it will be available.

2 Likes