AbstractScriptPool

abstract class AbstractScriptPool<T : AbstractScript>(size: Int, nullGlobalContext: Boolean) : AbstractEnginePool<T>

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. Subclasses populate the pool with populate in their init block. AbstractEnginePool describes borrowing and closing.

Parameters

size

the number of script instances in the pool; must be positive

nullGlobalContext

if true, resets the global scope bindings to null when recycling

Type Parameters

T

the concrete type of AbstractScript managed by this pool

Throws

if size is not positive

Constructors

Link copied to clipboard
constructor(size: Int, nullGlobalContext: Boolean)

Properties

Link copied to clipboard

Returns an approximate, point-in-time indication of whether the pool currently has no instances available. 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.

Link copied to clipboard
val size: Int

Functions

Link copied to clipboard
open override fun close()

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.

Link copied to clipboard
suspend fun <R> eval(block: T.() -> R): R

Suspends until a script instance can be borrowed, runs block on it, and returns the instance to the pool afterwards, even if block throws.