Commit 01e1819f authored by Mygod's avatar Mygod

Fix ambiguous coroutineContext

parent 6e9f445d
...@@ -66,7 +66,7 @@ tasks.register<Exec>("cargoClean") { ...@@ -66,7 +66,7 @@ tasks.register<Exec>("cargoClean") {
tasks.clean.dependsOn("cargoClean") tasks.clean.dependsOn("cargoClean")
dependencies { dependencies {
val coroutinesVersion = "1.3.6" val coroutinesVersion = "1.3.7"
val roomVersion = "2.2.5" val roomVersion = "2.2.5"
val workVersion = "2.4.0-beta01" val workVersion = "2.4.0-beta01"
......
...@@ -95,9 +95,7 @@ class SubscriptionService : Service(), CoroutineScope { ...@@ -95,9 +95,7 @@ class SubscriptionService : Service(), CoroutineScope {
} }
Core.notification.notify(NOTIFICATION_ID, notification.build()) Core.notification.notify(NOTIFICATION_ID, notification.build())
counter = 0 counter = 0
val workers = urls.asIterable().map { url -> val workers = urls.asIterable().map { url -> fetchJsonAsync(url, urls.size(), notification) }
async(Dispatchers.IO) { fetchJson(url, urls.size(), notification) }
}
try { try {
val localJsons = workers.awaitAll() val localJsons = workers.awaitAll()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
...@@ -127,20 +125,20 @@ class SubscriptionService : Service(), CoroutineScope { ...@@ -127,20 +125,20 @@ class SubscriptionService : Service(), CoroutineScope {
return START_NOT_STICKY 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) val tempFile = File.createTempFile("subscription-", ".json", cacheDir)
try { try {
(url.openConnection() as HttpURLConnection).useCancellable { (url.openConnection() as HttpURLConnection).useCancellable {
tempFile.outputStream().use { out -> inputStream.copyTo(out) } tempFile.outputStream().use { out -> inputStream.copyTo(out) }
} }
return tempFile tempFile
} catch (e: IOException) { } catch (e: IOException) {
Timber.d(e) Timber.d(e)
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
Toast.makeText(this@SubscriptionService, e.readableMessage, Toast.LENGTH_LONG).show() Toast.makeText(this@SubscriptionService, e.readableMessage, Toast.LENGTH_LONG).show()
} }
if (!tempFile.delete()) tempFile.deleteOnExit() if (!tempFile.delete()) tempFile.deleteOnExit()
return null null
} finally { } finally {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
counter += 1 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