1 | import { Resource } from './pool.js';
|
2 |
|
3 | export abstract class ResourceDecorator<T extends Resource> implements Resource {
|
4 | protected innerResource: T;
|
5 |
|
6 | constructor(private readonly producer: () => T) {
|
7 | this.innerResource = producer();
|
8 | }
|
9 |
|
10 | public async init(): Promise<void> {
|
11 | await this.innerResource.init?.();
|
12 | }
|
13 |
|
14 | public async dispose(): Promise<void> {
|
15 | await this.innerResource.dispose?.();
|
16 | }
|
17 | |
18 |
|
19 |
|
20 |
|
21 | protected async recover(): Promise<void> {
|
22 | await this.dispose();
|
23 | this.innerResource = this.producer();
|
24 | return this.init();
|
25 | }
|
26 | }
|