mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-01-15 07:21:07 +00:00
17 lines
332 B
JavaScript
17 lines
332 B
JavaScript
|
export default class CircularPool {
|
||
|
constructor(fn, size) {
|
||
|
this._cursor = 0;
|
||
|
this._data = new Array(size);
|
||
|
|
||
|
for (let i = 0; i < size; ++i) {
|
||
|
this._data[i] = fn();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
request() {
|
||
|
let item = this._data[this._cursor];
|
||
|
this._cursor = (this._cursor + 1) % this._data.length;
|
||
|
|
||
|
return item;
|
||
|
}
|
||
|
}
|