| 97 | * @param requestCtx - Request context |
| 98 | */ |
| 99 | export async function getPooledValue<T>( |
| 100 | poolingService: PoolingService<T> | Pool<T>, |
| 101 | requestCtx?: Context, |
| 102 | ): Promise<PooledValue<T>> { |
| 103 | let value: T; |
| 104 | if (poolingService instanceof PoolingService) { |
| 105 | value = await poolingService.acquire(requestCtx); |
| 106 | } else { |
| 107 | value = await poolingService.acquire(); |
| 108 | } |
| 109 | const pool = |
| 110 | poolingService instanceof PoolingService |
| 111 | ? poolingService.pool |
| 112 | : poolingService; |
| 113 | return { |
| 114 | pool, |
| 115 | value, |
| 116 | async release() { |
| 117 | return poolingService.release(value); |
| 118 | }, |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * A singleton service to maintain a pool of resources. This pool service can |