Page MenuHomeSealhub

BufferedPool.js
No OneTemporary

BufferedPool.js

function bufferedPool(getter, picker) {
let pool = [];
let promiseOfPool = getter().then(results => {
pool = results;
return pool;
});
return function() {
return promiseOfPool.then(function() {
if (pool.length === 0) {
throw new Error("Empty array");
}
return picker(pool);
});
};
}
export function popRandomElement(array) {
let index = Math.floor(Math.random() * array.length);
let lastIndex = array.length - 1;
[array[index], array[lastIndex]] = [array[lastIndex], array[index]];
return array.pop();
}
export default bufferedPool;

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 02:20 (22 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
548089
Default Alt Text
BufferedPool.js (655 B)

Event Timeline