Skip to content

Commit

Permalink
feat(lrupool): add a LRU pool service
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Jul 15, 2024
1 parent 6b4b1a6 commit cf3a8cf
Show file tree
Hide file tree
Showing 7 changed files with 1,307 additions and 713 deletions.
48 changes: 48 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<dd><p>Instantiate the logging service</p>
</dd>
<dt><a href="#initRandom">initRandom(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the LRU Pool service</p>
</dd>
<dt><a href="#initRandom">initRandom(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the random service</p>
</dd>
<dt><a href="#initResolve">initResolve(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
Expand Down Expand Up @@ -346,6 +349,51 @@ log('debug', 'Luke, I am your father!')
```
<a name="initRandom"></a>
## initRandom(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the LRU Pool service
**Kind**: global function
**Returns**: <code>Promise.&lt;function()&gt;</code> - A promise of the LRUPool service
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> | | The services to inject |
| [services.log] | <code>Object</code> | <code>noop</code> | A logging function |
**Example**
```js
import {
DEFAULT_LOGGER,
initLog,
initLRUPool
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const random = await initLRUPool({
MAX_POOL_SIZE: 50,
poolManager: {
// ...
},
log,
});
```
<a name="initRandom..random"></a>
### initRandom~random() ⇒ <code>number</code>
Returns a new random number
**Kind**: inner method of [<code>initRandom</code>](#initRandom)
**Returns**: <code>number</code> - The random number
**Example**
```js
random()
// Prints: 0.3141592653589793
```
<a name="initRandom"></a>
## initRandom(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the random service
Expand Down
13 changes: 13 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
7. [Code generator](#17-code-generator)
8. [Lock](#18-lock)
9. [Counter](#19-counter)
10. [LRU Pool](#110-lru-pool)


## 1. Services
Expand Down Expand Up @@ -140,3 +141,15 @@ The count are returned asynchronously in order

[See in context](./src/services/counter.ts#L20-L29)



### 1.10. LRU Pool

The `lruPool` service allows to maintain a pool of
resources. It is meant to be used with resources
like file descriptors that are limited in most
OSes but are pointing to completely different
kind of resources (files paths varies).

[See in context](./src/services/lruPool.ts#L33-L40)

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ complete dependency injection tool but can also be used by hand.
<dd><p>Instantiate the logging service</p>
</dd>
<dt><a href="#initRandom">initRandom(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the LRU Pool service</p>
</dd>
<dt><a href="#initRandom">initRandom(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the random service</p>
</dd>
<dt><a href="#initResolve">initResolve(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
Expand Down Expand Up @@ -376,6 +379,51 @@ log('debug', 'Luke, I am your father!')
```
<a name="initRandom"></a>
## initRandom(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the LRU Pool service
**Kind**: global function
**Returns**: <code>Promise.&lt;function()&gt;</code> - A promise of the LRUPool service
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| services | <code>Object</code> | | The services to inject |
| [services.log] | <code>Object</code> | <code>noop</code> | A logging function |
**Example**
```js
import {
DEFAULT_LOGGER,
initLog,
initLRUPool
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const random = await initLRUPool({
MAX_POOL_SIZE: 50,
poolManager: {
// ...
},
log,
});
```
<a name="initRandom..random"></a>
### initRandom~random() ⇒ <code>number</code>
Returns a new random number
**Kind**: inner method of [<code>initRandom</code>](#initRandom)
**Returns**: <code>number</code> - The random number
**Example**
```js
random()
// Prints: 0.3141592653589793
```
<a name="initRandom"></a>
## initRandom(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the random service
Expand Down
Loading

0 comments on commit cf3a8cf

Please sign in to comment.