
com.simiacryptus.util.RunWithPermit.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jo-penai Show documentation
Show all versions of jo-penai Show documentation
A Java client for OpenAI's API
The newest version!
package com.simiacryptus.util
import org.slf4j.LoggerFactory
import java.util.concurrent.Semaphore
private val logger = LoggerFactory.getLogger("RunWithPermitLogger")
fun Semaphore.runWithPermit(function: () -> String): String {
logger.info("Attempting to acquire permit...")
this.acquire()
logger.info("Permit acquired.")
try {
return function()
} finally {
logger.info("Releasing permit.")
this.release()
logger.info("Permit released.")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy