See: 4-improved.js
Signature poolify(factory, min, norm, max)
factory
- call to instantiate pool itemmin
- minimum amount to allocate newnorm
- preallocated amountmax
- maximum amount to limit pool
Object Pool
Home Page: https://www.youtube.com/TimurShemsedinov
License: MIT License
See: 4-improved.js
Signature poolify(factory, min, norm, max)
factory
- call to instantiate pool itemmin
- minimum amount to allocate newnorm
- preallocated amountmax
- maximum amount to limit poolPool from 9-exclusive.js up to b-timeout.js
const pool = new Pool();
pool.add({ item: 1 });
pool.add({ item: 2 });
let x1 = pool.capture();
const x2 = pool.capture();
pool.release(x1);
x1 = pool.capture();
pool.release(x1);
const bottom = pool.capture(); //infinite loop in next(1)
release(item) {
const index = this.items.indexOf(item);
if (index < 0) throw new Error('Pool: release unexpected item');
if (this.free[index]) throw new Error('Pool: release not captured');
this.free[index] = true;
this.available++;
if (this.queue.length > 0) {
const { resolve, timer } = this.queue.shift();
clearTimeout(timer);
if (resolve) setTimeout(resolve, 0, item);
}
}
error - we should not free released item if we resolve it for user in queue
release(item) {
const index = this.items.indexOf(item);
if (index < 0) throw new Error('Pool: release unexpected item');
if (this.free[index]) throw new Error('Pool: release not captured');
if (this.queue.length > 0) {
const { resolve, timer } = this.queue.shift();
clearTimeout(timer);
if (resolve) setTimeout(resolve, 0, item);
} else {
this.free[index] = true;
this.available++;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.