use

fun <T> Resource.use(f: () -> T): T

Registers the resource globally, and then invokes f. The resource is unregistered before returning