@ SuppressWarnings ( "WeakerAccess" ) public final < R > Optional < R > apply ( Timeout timeout , Function < T , R > function ) throws InterruptedException { T obj = claim ( timeout ) ; if ( obj == null ) { return Optional . empty ( ) ; } try { return Optional . ofNullable ( function . apply ( obj ) ) ; } finally { obj . release ( ) ; } }
Claim an object from the pool and apply the given function to it returning the result and releasing the object back to the pool .