MCPcopy Index your code
hub / github.com/Effect-TS/effect / makeWith

Function makeWith

packages/effect/src/internal/pool.ts:35–77  ·  view source on GitHub ↗
(options: {
  readonly acquire: Effect<A, E, R>
  readonly min: number
  readonly max: number
  readonly concurrency?: number | undefined
  readonly targetUtilization?: number | undefined
  readonly strategy: Strategy<A, E>
})

Source from the content-addressed store, hash-verified

33
34/** @internal */
35export const makeWith = <A, E, R>(options: {
36 readonly acquire: Effect<A, E, R>
37 readonly min: number
38 readonly max: number
39 readonly concurrency?: number | undefined
40 readonly targetUtilization?: number | undefined
41 readonly strategy: Strategy<A, E>
42}): Effect<Pool<A, E>, never, Scope | R> =>
43 core.uninterruptibleMask((restore) =>
44 core.flatMap(core.context<R | Scope>(), (context) => {
45 const scope = Context.get(context, fiberRuntime.scopeTag)
46 const acquire = core.mapInputContext(
47 options.acquire,
48 (input) => Context.merge(context, input)
49 ) as Effect<
50 A,
51 E,
52 Scope
53 >
54 const pool = new PoolImpl<A, E>(
55 scope,
56 acquire,
57 options.concurrency ?? 1,
58 options.min,
59 options.max,
60 options.strategy,
61 Math.min(Math.max(options.targetUtilization ?? 1, 0.1), 1)
62 )
63 const initialize = core.tap(fiberRuntime.forkDaemon(restore(pool.resize)), (fiber) =>
64 scope.addFinalizer(() => core.interruptFiber(fiber)))
65 const runStrategy = core.tap(fiberRuntime.forkDaemon(restore(options.strategy.run(pool))), (fiber) =>
66 scope.addFinalizer(() =>
67 core.interruptFiber(fiber)
68 ))
69 return core.succeed(pool).pipe(
70 core.zipLeft(scope.addFinalizer(() =>
71 pool.shutdown
72 )),
73 core.zipLeft(initialize),
74 core.zipLeft(runStrategy)
75 )
76 })
77 )
78
79/** @internal */
80export const make = <A, E, R>(options: {

Callers 2

makeFunction · 0.70
makeWithTTLFunction · 0.70

Calls 7

restoreFunction · 0.85
mergeMethod · 0.80
contextMethod · 0.65
getMethod · 0.65
addFinalizerMethod · 0.65
pipeMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected