Companion

object Companion

Functions

Link copied to clipboard
fun <A> defer(f: suspend () -> Resource<A>): Resource<A>
Link copied to clipboard
operator fun <A> invoke(acquire: suspend () -> A, release: suspend (A, ExitCase) -> Unit): Resource<A>

Construct a Resource from an allocating function acquire and a release function release.

Link copied to clipboard
fun <A> just(r: A): Resource<A>

Create a Resource from a pure value A.

Extensions

Link copied to clipboard
fun <A : AutoCloseable> Resource.Companion.fromAutoCloseable(f: suspend () -> A): Resource<A>

Creates a Resource from an AutoCloseable, which uses AutoCloseable.close for releasing.

Link copied to clipboard
fun <A : Closeable> Resource.Companion.fromCloseable(f: suspend () -> A): Resource<A>

Creates a Resource from an Closeable, which uses Closeable.close for releasing.

Link copied to clipboard
fun Resource.Companion.fromExecutor(f: suspend () -> ExecutorService): Resource<CoroutineContext>

Creates a single threaded CoroutineContext as a Resource. Upon release an orderly shutdown of the ExecutorService takes place in which previously submitted tasks are executed, but no new tasks will be accepted.

Link copied to clipboard
fun Resource.Companion.singleThreadContext(name: String): Resource<CoroutineContext>

Creates a single threaded CoroutineContext as a Resource. Upon release an orderly shutdown of the ExecutorService takes place in which previously submitted tasks are executed, but no new tasks will be accepted.