In the network layer of my app I have to save a bu...
# android
s
In the network layer of my app I have to save a bunch of values in shared preference. These values might be saved from several locations in the app. I am planning to put this task inside a WorkManager.
Copy code
```    CoroutineScope(coroutineContext).launch {
        val saveProfileWork = OneTimeWorkRequestBuilder<SaveProfileWorker>()
                        .setInputData(
                            workDataOf(
                                "IMAGE_URI" to "http://..."
                            )
                        )
                        .build()
        val request = WorkManager.getInstance(context).beginWith(saveProfileWork).enqueue().await()
        // post success
        return@launch
    }
``` 1. As far as my understanding goes launch starts a coroutine and await() awaits the result from another builder aynch(). This means I will be creating a coroutine inside a coroutine. Outer would be part of my network layer and inner one would be work manager's. I am not sure what should be done here. This also sounds like I might have issue handling exception. 2. How do I get success value from await call? If it asynchronous then return will end the outer launch coroutine.
s
Thanks. This made sense. I have just moved that whole code into a common suspend function which I can reuse from multiple places as per need.
👍🏼 1