eval

suspend fun eval(expr: String): Boolean

Suspends until an evaluator can be borrowed from the pool, evaluates expr, and recycles the evaluator afterwards. Suspends (rather than blocking) when all size evaluators are in use.

Only the wait for an evaluator is cancellable. The expression runs on the calling thread, so once it starts, neither withTimeout nor cancelling the caller can stop it: it runs to completion, holding its evaluator. Use the overload that takes a timeout for expressions that might not finish.

Return

the boolean result of the evaluation

Parameters

expr

the expression to evaluate

Throws

kotlinx.coroutines.channels.ClosedReceiveChannelException

if the pool has been closed


suspend fun eval(expr: String, timeout: Duration): Boolean

Like eval, but runs the expression on a thread of its own and waits at most timeout for it; the wait for an evaluator does not count toward timeout. If the expression does not finish in time, its thread is interrupted, the evaluator is taken out of the pool for good and a fresh one takes its place, and a ScriptTimeoutException is thrown. Cancelling the caller while the expression runs stops it the same way.

An engine that ignores the interrupt keeps the thread running until the expression returns, if it ever does; the evaluator is closed then.

Return

the boolean result of the evaluation

Parameters

expr

the expression to evaluate

timeout

how long the expression may run; must be positive

Throws

if the expression does not finish within timeout

kotlinx.coroutines.channels.ClosedReceiveChannelException

if the pool has been closed