MCPcopy Create free account
hub / github.com/Effect-TS/effect / allocate

Function allocate

packages/effect/src/Pool.ts:563–588  ·  view source on GitHub ↗
(self: Pool<A, E>)

Source from the content-addressed store, hash-verified

561 })
562
563const allocate = <A, E>(self: Pool<A, E>): Effect.Effect<PoolItem<A, E>> =>
564 Effect.acquireUseRelease(
565 Scope.make(),
566 (scope) =>
567 self.config.acquire.pipe(
568 Scope.provide(scope),
569 Effect.exit,
570 Effect.flatMap((exit) => {
571 const item: PoolItem<A, E> = {
572 exit,
573 finalizer: Effect.catchCause(Scope.close(scope, exit), reportUnhandledError),
574 refCount: 0,
575 disableReclaim: false
576 }
577 self.state.items.add(item)
578 self.state.available.add(item)
579 return Effect.as(
580 exit._tag === "Success"
581 ? self.config.strategy.onAcquire(item)
582 : Effect.flatMap(item.finalizer, () => self.config.strategy.onAcquire(item)),
583 item
584 )
585 })
586 ),
587 (scope, exit) => exit._tag === "Failure" ? Scope.close(scope, exit) : Effect.void
588 )
589
590const currentUsage = <A, E>(self: Pool<A, E>) => {
591 let count = self.state.waiters

Callers 1

resizeLoopFunction · 0.70

Calls 5

makeMethod · 0.65
pipeMethod · 0.65
closeMethod · 0.65
addMethod · 0.65
provideMethod · 0.45

Tested by

no test coverage detected