UNPKG

round-robin-distributor

Version:

A brain dead module that would take array of urls and do a round robin distribution when calling donwstream

22 lines (20 loc) 537 B
class RoundRobinDistributor{ constructor(urlList){ if(!Array.isArray(urlList)){ throw 'URL List parameter should be an Array'; } this.index = 0; this.urls = urlList; this.urlListTrueLength = this.urls.length - 1; } nextUrl(){ if(this.urlListTrueLength == 0){ return this.urls[0]; } else if(this.index > this.urlListTrueLength){ this.index = 0; } return this.urls[this.index++]; } } module.exports = RoundRobinDistributor;