Initial prototype
This commit is contained in:
23
lib/Selectors.js
Normal file
23
lib/Selectors.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
class RoundRobinSelector {
|
||||
constructor () {
|
||||
this.current = -1
|
||||
}
|
||||
|
||||
select (connections) {
|
||||
if (++this.current >= connections.length) {
|
||||
this.current = 0
|
||||
}
|
||||
return connections[this.current]
|
||||
}
|
||||
}
|
||||
|
||||
class RandomSelector {
|
||||
select (connections) {
|
||||
const index = Math.floor(Math.random() * connections.length)
|
||||
return connections[index]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { RoundRobinSelector, RandomSelector }
|
||||
Reference in New Issue
Block a user