Below is a definition of a tryWith function
def tryWith[R, T <: AutoCloseable](resource: T)(doWork: T => R): R = { try { doWork(resource) } finally { try { if (resource != null) { resource.close() } } catch { case e: Exception => throw e } } }
There are 2 functions. The first function takes an AutoCloseable resource. The second function uses the resource. The try finally block ensures the resource is closed once the second function returns.
Below is how the function can be used:
val request = new HttpGet("http://www.google.com") val statusCode = tryWith(client.execute(request)){response => response.getStatusLine.getStatusCode }
client.execute() returns an AutoCloseable Response, which will be automatically closed. After return the StatusCode.
Really nice blog,i enjoyed your infomations. Thank you and i will expect more in future.
ReplyDeleteJAVA Training in Chennai
Java training institute in chennai
Selenium Training in Chennai
Hadoop Training in Chennai
Python Training in Chennai
Software testing training in chennai
JAVA Training in Chennai
Java Training in Velachery
Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
I just see your blog, in this content was very valuable and very interesting. I am very happy to see your post, I want more addition post from your great blog...
ReplyDeleteUnix Training in Chennai
Unix Course in Chennai
Excel Training in Chennai
Corporate Training in Chennai
Tableau Training in Chennai
Social Media Marketing Courses in Chennai
Spark Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Pega Training in Chennai
The article is so informative. This is more helpful. Thanks for sharing.
ReplyDeleteLearn best software testing online certification course class in chennai with placement
Best selenium testing online course training in chennai
Best online software testing training course institute in chennai with placement
Magento 2 Developer course training institute in chennai
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeletethanks for your information really good and very nice web design company in velachery
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.
ReplyDeleteBloglovin Mystrikingly Justpaste Mystrikingly
Đặt vé tại phòng vé Aivivu, tham khảo
ReplyDeletesăn vé máy bay giá rẻ đi Mỹ
giá vé máy bay từ mỹ về vn
các đường bay từ canada về việt nam
bay nhật việt
Lịch bay từ Seoul đến Hà Nội
Vé máy bay từ Đài Loan về VN
giá khách sạn cách ly
شركة شراء اثاث مستعمل بالرياض
ReplyDelete