Skip to content

Commit 01e1819

Browse files
committed
Fix ambiguous coroutineContext
1 parent 6e9f445 commit 01e1819

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

core/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ tasks.register<Exec>("cargoClean") {
6666
tasks.clean.dependsOn("cargoClean")
6767

6868
dependencies {
69-
val coroutinesVersion = "1.3.6"
69+
val coroutinesVersion = "1.3.7"
7070
val roomVersion = "2.2.5"
7171
val workVersion = "2.4.0-beta01"
7272

core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ class SubscriptionService : Service(), CoroutineScope {
9595
}
9696
Core.notification.notify(NOTIFICATION_ID, notification.build())
9797
counter = 0
98-
val workers = urls.asIterable().map { url ->
99-
async(Dispatchers.IO) { fetchJson(url, urls.size(), notification) }
100-
}
98+
val workers = urls.asIterable().map { url -> fetchJsonAsync(url, urls.size(), notification) }
10199
try {
102100
val localJsons = workers.awaitAll()
103101
withContext(Dispatchers.Main) {
@@ -127,20 +125,20 @@ class SubscriptionService : Service(), CoroutineScope {
127125
return START_NOT_STICKY
128126
}
129127

130-
private suspend fun fetchJson(url: URL, max: Int, notification: NotificationCompat.Builder): File? {
128+
private fun fetchJsonAsync(url: URL, max: Int, notification: NotificationCompat.Builder) = async(Dispatchers.IO) {
131129
val tempFile = File.createTempFile("subscription-", ".json", cacheDir)
132130
try {
133131
(url.openConnection() as HttpURLConnection).useCancellable {
134132
tempFile.outputStream().use { out -> inputStream.copyTo(out) }
135133
}
136-
return tempFile
134+
tempFile
137135
} catch (e: IOException) {
138136
Timber.d(e)
139137
launch(Dispatchers.Main) {
140138
Toast.makeText(this@SubscriptionService, e.readableMessage, Toast.LENGTH_LONG).show()
141139
}
142140
if (!tempFile.delete()) tempFile.deleteOnExit()
143-
return null
141+
null
144142
} finally {
145143
withContext(Dispatchers.Main) {
146144
counter += 1

0 commit comments

Comments
 (0)