A helper for Kotlin users that simply closes the connection after the block has executed. Be careful not to over-use this, as setting up and closing connections takes time.