jackfirth / racket-disposable

An experimental Racket library providing an abstraction for values associated with external resources that allows automatic resource pooling, per-thread virtual construction, and monadic composition
Apache License 2.0
7 stars 0 forks source link

Add pool preallocation #57

Open jackfirth opened 7 years ago

jackfirth commented 7 years ago

Sometimes a pool should be "warmed up" by preallocating a bunch of idle resources. A #:soft-min-idle keyword arg to disposable-pool should do the trick. When the pool is first created, that many resources should be withdrawn and immediately returned asynchronously. Then whenever an idle value is reused for a future allocation, if not enough idle values are present to satisfy the minimum, a value should be created and added asynchronously. The minimum is only a "soft" minimum because in order to prevent blocking, threads should be able to request an idle value and immediately begin work without blocking on the creation of a replacement value. Additionally, if the pool is at capacity there might be enough consumers of values that the soft minimum of idle values can't be satisfied without going over capacity.