https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

Nikola Milovic

02/05/2021, 12:41 PM
Hey everyone, looking at the docs for CoroutineWorker from WorkManager, I came across this
Copy code
class CoroutineDownloadWorker(
    context: Context,
    params: WorkerParameters
) : CoroutineWorker(context, params) {

    override suspend fun doWork(): Result {
        withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            val data = downloadSynchronously("<https://www.google.com>")
            saveData(data)
            return Result.success()
        }
    }
}
Which wouldn't work? As it has to be
return@withContext
and you need a return value outside of it? Or I am I missing something
m

Marc Knaup

02/05/2021, 12:45 PM
Move the return to before
withContext
🙂
Copy code
return withContext… {
   …
   Result.success()
}
n

Nikola Milovic

02/05/2021, 12:46 PM
Oh thank you
2 Views