AbstractEnginePool

abstract class AbstractEnginePool<T : AbstractEngine>(val size: Int) : Closeable

Abstract base class for a fixed-size pool of script engines, shared by AbstractScriptPool and AbstractExprEvaluatorPool.

Uses a coroutine Channel as a bounded buffer of instances. Subclasses create the instances with populate in their init block, borrow one with withInstance, and prepare a returned instance for its next borrower in reset. An instance handed to a borrower that is cancelled before it resumes goes back into the pool instead of being lost. Closing the pool closes its instances.

Parameters

size

the number of instances in the pool; must be positive

Type Parameters

T

the type of engine in the pool

Throws

if size is not positive

Inheritors

Constructors

Link copied to clipboard
constructor(size: Int)

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.