AbstractScriptPool
Abstract base class for a pool of AbstractScript instances.
When a script is returned to the pool, AbstractScript.resetForReuse prepares it for the next borrower. That clears the variables the previous borrower added and the declarations it made, not the interpreter's own state or the JVM's: a module attribute set in Jython, or a static field set anywhere, is still there for the next borrower. Subclasses populate the pool with populate in their init block. AbstractEnginePool describes borrowing and closing.
Parameters
the number of script instances in the pool; must be positive
if true, resets the global scope bindings to null when recycling
Type Parameters
the concrete type of AbstractScript managed by this pool
Throws
if size is not positive
Properties
Returns an approximate, point-in-time indication of whether every place in the pool is currently borrowed, so that a borrower would have to wait. Delegates to Channel.isEmpty, which is racy under concurrent borrow/recycle and may return a stale result, so do not rely on it for correctness.
Functions
Closes the pool and the instances it holds. An instance still borrowed is closed when it is returned, and later borrows throw kotlinx.coroutines.channels.ClosedReceiveChannelException. Every instance the pool holds is closed even when closing one throws; the first failure then propagates, with the later ones attached as suppressed. An instance whose timed evaluation was abandoned is closed when that evaluation returns, if it ever does.
Suspends until a script instance can be borrowed, runs block on it, and returns the instance to the pool afterwards, even if block throws.
Like eval, but runs block on a thread of its own and waits at most timeout for it; the wait for an instance does not count toward timeout. If block does not finish in time, its thread is interrupted, the instance is taken out of the pool for good and a fresh one takes its place, and a ScriptTimeoutException is thrown. Cancelling the caller while block runs stops it the same way.