refactor(RouVideo): use 'use' for resource management in network calls

This commit is contained in:
Cuong-Tran
2025-05-23 01:13:37 +07:00
committed by Cuong-Tran
parent 029f0709f9
commit 8c28ae8888

View File

@@ -108,7 +108,7 @@ class RouVideo(
async {
client.newCall(relatedAnimeListRequest(anime))
.execute()
.let { response ->
.use { response ->
relatedAnimeListParse(response)
}
},
@@ -324,11 +324,13 @@ class RouVideo(
runCatching {
client.newCall(tagsListRequest())
.execute()
.asJsoup()
.let(::tagsListParse)
.let { tags ->
if (tags.isNotEmpty()) {
tagsArray = tags
.use {
it.asJsoup()
.let(::tagsListParse)
.let { tags ->
if (tags.isNotEmpty()) {
tagsArray = tags
}
}
}
}.onFailure { it.printStackTrace() }
@@ -367,13 +369,15 @@ class RouVideo(
runCatching {
client.newCall(hotSearchRequest())
.execute()
.asJsoup()
.let(::hotSearchParse)
.let {
hotSearch = if (!this::hotSearch.isInitialized) {
it
} else {
hotSearch.plus(it)
.use {
it.asJsoup()
.let(::hotSearchParse)
.let {
hotSearch = if (!this::hotSearch.isInitialized) {
it
} else {
hotSearch.plus(it)
}
}
}
}.onFailure { it.printStackTrace() }
@@ -397,7 +401,7 @@ class RouVideo(
?.groupValues?.get(1)
return client.newCall(animeDetailsRequest(anime))
.execute()
.let { response ->
.use { response ->
parseAnimeDetails(response, resolution)
}
}