0.0.0 • Published 9 years ago
bassine v0.0.0
Bassine
An asynchronous and bounded resource pool for generic objects
Bassine provides an implementation of a resource pool aimed at allowing bounded construction and re-use of expensive-to-allocate objects. This is for example the case with objects that spawn and control external processes such as database connections or headless browsers.
Contents
Installation
$ npm install --save bassineUsage
Try out Bassine in your browser
const pool = new Pool(2, async i => i);
const one = await pool.borrow();
// => 1
const two = await pool.borrow();
// => 2
pool.return(one);
pool.return(two);API
Pool
constructor
Create a new pool.
Parameters
limitNumber The limit on the number of items available in the pool.factoryFunction The factory function for constructing items for the pool.
Examples
const pool = new Pool(10, async i => `Item ${i}`);borrow
Borrow an item from this pool.
Examples
const borrowed = await pool.borrow();
// => 'Item 0'Returns Promise A promise that will resolve with the item when available.
return
Return an item to this pool.
Parameters
itemany The item to return to this pool.
Examples
const returned = pool.return(borrowed);
// => trueReturns Boolean true if the item was accepted by this pool, otherwise false.
License
Copyright © 2016 Kasper Kronborg Isager. Licensed under the terms of the MIT license.
0.0.0
9 years ago