WRRPool
WRRPool is a Weighted Round Robin resource pool
Using
npm install wrr-pool
Basic usage
var WRRPool = require('wrr-pool');
var pool = new WRRPool();
pool.add('A', 4);
pool.add('B', 3);
pool.add('C', 2);
pool.next();
pool.next();
pool.next();
pool.next();
pool.next();
pool.next();
pool.next();
pool.next();
pool.next();
Get resource and its weight
var pool = new WRRPool();
pool.add({ id: 1 }, 4);
pool.add({ id: 2 }, 3);
pool.add({ id: 3 }, 2);
pool.get({ id: 2 });
var pool = new WRRPool();
pool.add({ id: 1 }, 4);
pool.add({ id: 2 }, 3);
pool.add({ id: 3 }, 2);
pool.get(function (v){ return v.id === 2; });
Update resource value and/or weight
var pool = new WRRPool();
pool.add('A', 4);
pool.add('B', 3);
pool.add('C', 2);
pool.update(function (v) { return v === 'B';}, 'B1', 4);
Remove resource from pool
var pool = new WRRPool();
pool.add('A', 4);
pool.add('B', 3);
pool.add('C', 2);
pool.remove(function (v) { return v === 'C';});
License
MIT