I want to upload some objects to a server. I'm using work manager and uniqueWork to avoid uploading duplicate objects. There is a constraint on the work so that they only operate when there is internet connectivity. The problem is I want each of these objects to upload one at a time, but all the work happens at once.
I know that I can use beginWith and workContinuations to perform work in sequence, but unfortunately multiple objects can be created at different times, so I do not have access to all the work at the time of creating the work.
val workRequest = OneTimeWorkRequestBuilder<UploadWorker>()
.setConstraints(networkConstraint)
.build()
WorkManager.getInstance()
.enqueueUniqueWork(uniqueName, ExistingWorkPolicy.KEEP, workRequest)
I assumed enqueue
meant that all the work would happen one at a time like a queue. Is there a way to make it work that way?