@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
56 lines (38 loc) • 2.64 kB
Markdown
---
lang: en
title: 'API docs: pooling.poolingservice'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/extensions/pooling
permalink: /doc/en/lb4/apidocs.pooling.poolingservice.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/pooling](./pooling.md) > [PoolingService](./pooling.poolingservice.md)
## PoolingService class
A singleton service to maintain a pool of resources. This pool service can be bound to different keys to represent multiple pools. Each binding is a singleton so that the state stays the same for injections into multiple instances for other artifacts.
<b>Signature:</b>
```typescript
export declare class PoolingService<T> implements LifeCycleObserver
```
<b>Implements:</b> [LifeCycleObserver](./core.lifecycleobserver.md)
## Remarks
Some resources can be expensive to create/start. For example, a datasource has overhead to connect to the database. There will be performance penalty to use `TRANSIENT` scope and creates a new instance per request. But it is not feasible to be a singleton for some use cases, for example, each request may have different security contexts.
The pool service observes life cycle events to start and stop.
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(context, options)](./pooling.poolingservice._constructor_.md) | | Constructs a new instance of the <code>PoolingService</code> class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [context](./pooling.poolingservice.context.md) | | [Context](./context.context.md) | |
| [pool](./pooling.poolingservice.pool.md) | | Pool<T> | The resource pool |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [acquire(requestCtx)](./pooling.poolingservice.acquire.md) | | Acquire a new instance |
| [destroy(resource)](./pooling.poolingservice.destroy.md) | | Destroy a resource from the pool |
| [release(resource)](./pooling.poolingservice.release.md) | | Release the resource back to the pool. |
| [run(task, requestCtx)](./pooling.poolingservice.run.md) | | Run the task with an acquired resource from the pool. If task is completed successfully, the resource is returned to the pool. Otherwise, the resource is destroyed. |
| [start()](./pooling.poolingservice.start.md) | | Start the pool |
| [stop()](./pooling.poolingservice.stop.md) | | Stop the pool |