Returns the object being leased by the pool.
Returns the object being leased by the pool. Throws an java.lang.IllegalStateException if the lease has already been released or invalidated.
the object being leased by the pool.
Invalidates the current lease.
Invalidates the current lease. The object is "destroyed" and is no longer eligible to be returned to the pool. Additionally, the number of live objects in the pool is decremented.
If the lease has already been released or invalidated this method does nothing.
Releases the object back to the pool for reuse.
Releases the object back to the pool for reuse. When releasing an object it is mandatory that there are no references to the returned object.
If the lease has already been released or invalidated this method does nothing.
Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.
Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.
If needed, it is possible to invalidate the lease from inside the provided function, for example:
val lease = pool.acquire() val x = lease.use { v => if (/* invalid condition */) { lease.invalidate(); None } else Some(/* result */) }
It is important that no references are kept to the leased object after
this method finishes. For example, the following code is invalid since the
variable x
holds a reference to an object that was returned to the pool.
val lease = pool.acquire() val x = lease.use(identity)
the type of object returned by the function f
a function that uses the value stored in the lease to produce a new value
the value produced by the function f
.
A lease on an object requested from a io.github.andrebeat.pool.Pool allowing the object to be accessed and then released back to the pool when no longer needed.
the type of object stored in this lease