mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
24 lines
470 B
JavaScript
24 lines
470 B
JavaScript
function ImagePool(size) {
|
|
this.size = size
|
|
this.images = []
|
|
this.counter = 0
|
|
}
|
|
|
|
ImagePool.prototype.next = function() {
|
|
if (this.images.length < this.size) {
|
|
var image = new Image()
|
|
this.images.push(image)
|
|
return image
|
|
}
|
|
else {
|
|
if (this.counter >= this.size) {
|
|
// Reset for unlikely but theoretically possible overflow.
|
|
this.counter = 0
|
|
}
|
|
|
|
return this.images[this.counter++ % this.size]
|
|
}
|
|
}
|
|
|
|
module.exports = ImagePool
|