Matt Thiffault
10/10/2019, 12:45 AMnwh
10/10/2019, 12:51 AMstreetsofboston
10/10/2019, 1:05 AMMatt Thiffault
10/10/2019, 1:06 AMnwh
10/10/2019, 1:10 AMwith
keyword in arguments and stuff and found myself very lostnfrankel
10/10/2019, 5:36 AMJetInstance
which has a shutdown
method
and wanted to use use()
on it
to automatically close()
it
with delegate and extension method, this is a breeze:
class CloseableJet(private val instance: JetInstance) : Closeable, JetInstance by instance {
override fun close() {
shutdown()
}
}
fun JetInstance.withCloseable() = CloseableJet(this)
now:
Jet.newJetClient().withCloseable().use {
it.newJob(pipeline(), config)
}
Matt Thiffault
10/10/2019, 6:06 PMstreetsofboston
10/10/2019, 6:07 PM