public class LazyPool<A>
A lazy pool of resources A.
Constructor and Description |
---|
LazyPool(kotlin.jvm.functions.Function1<? super A,kotlin.Unit> clear,
kotlin.jvm.functions.Function1<? super A,java.lang.Boolean> shouldReturnToPool,
java.lang.Integer bound,
kotlin.jvm.functions.Function0<? extends A> newInstance)
A lazy pool of resources A.
|
Modifier and Type | Method and Description |
---|---|
A |
borrow() |
java.lang.Iterable<A> |
close()
Closes the pool. Note that all borrowed instances must have been released before calling this function, otherwise
the returned iterable will be inaccurate.
|
void |
release(A instance) |
<R> R |
run(kotlin.jvm.functions.Function1<? super A,? extends R> withInstance) |
public LazyPool(kotlin.jvm.functions.Function1<? super A,kotlin.Unit> clear, kotlin.jvm.functions.Function1<? super A,java.lang.Boolean> shouldReturnToPool, java.lang.Integer bound, kotlin.jvm.functions.Function0<? extends A> newInstance)
A lazy pool of resources A.
clear
- If specified this function will be run on each borrowed instance before handing it over.shouldReturnToPool
- If specified this function will be run on each release to determine whether the instance
should be returned to the pool for reuse. This may be useful for pooled resources that dynamically grow during
usage, and we may not want to retain them forever.bound
- If specified the pool will be bounded. Once all instances are borrowed subsequent borrows will block until an
instance is released.newInstance
- The function to call to lazily newInstance a pooled resource.public A borrow()
public void release(A instance)
public java.lang.Iterable<A> close()
Closes the pool. Note that all borrowed instances must have been released before calling this function, otherwise the returned iterable will be inaccurate.
public <R> R run(kotlin.jvm.functions.Function1<? super A,? extends R> withInstance)