Commit 01e1819f authored by Mygod's avatar Mygod

Fix ambiguous coroutineContext

parent 6e9f445d
......@@ -66,7 +66,7 @@ tasks.register<Exec>("cargoClean") {
tasks.clean.dependsOn("cargoClean")
dependencies {
val coroutinesVersion = "1.3.6"
val coroutinesVersion = "1.3.7"
val roomVersion = "2.2.5"
val workVersion = "2.4.0-beta01"
......
......@@ -95,9 +95,7 @@ class SubscriptionService : Service(), CoroutineScope {
}
Core.notification.notify(NOTIFICATION_ID, notification.build())
counter = 0
val workers = urls.asIterable().map { url ->
async(Dispatchers.IO) { fetchJson(url, urls.size(), notification) }
}
val workers = urls.asIterable().map { url -> fetchJsonAsync(url, urls.size(), notification) }
try {
val localJsons = workers.awaitAll()
withContext(Dispatchers.Main) {
......@@ -127,20 +125,20 @@ class SubscriptionService : Service(), CoroutineScope {
return START_NOT_STICKY
}
private suspend fun fetchJson(url: URL, max: Int, notification: NotificationCompat.Builder): File? {
private fun fetchJsonAsync(url: URL, max: Int, notification: NotificationCompat.Builder) = async(Dispatchers.IO) {
val tempFile = File.createTempFile("subscription-", ".json", cacheDir)
try {
(url.openConnection() as HttpURLConnection).useCancellable {
tempFile.outputStream().use { out -> inputStream.copyTo(out) }
}
return tempFile
tempFile
} catch (e: IOException) {
Timber.d(e)
launch(Dispatchers.Main) {
Toast.makeText(this@SubscriptionService, e.readableMessage, Toast.LENGTH_LONG).show()
}
if (!tempFile.delete()) tempFile.deleteOnExit()
return null
null
} finally {
withContext(Dispatchers.Main) {
counter += 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment