Is it possible to get rid of nested Task generics?
For every continueWith
statement, a new Task
is added within the type. Every continuation is part of the type. Ideally I would return one Task which consecutively executes every single task and succeeds or fails as one.
Example
The first operations queries the groups of a user
private fun getGroupsSnapshot(): Task<QuerySnapshot> {
val userId = Auth.currentUser()!!.uid
val query = userGroupsQuery(groupsCollection, userId)
return query.get()
}
The second operation queries albums within those groups.
fun getAlbums(): Task<Task<List<Album>>> {
return getGroupsSnapshot().continueWith { task ->
val documentSnapshots = TaskUtils.getResult(task)
val albums = mutableListOf<Album>()
val fetchAlbumTasks = documentSnapshots.documents.map { document ->
Log.d(TAG, document["name"].toString())
document.reference.collection("albums").get().addOnCompleteListener { queryTask ->
albums.addAll(toObjects(Album::class.java, queryTask))
}
}
return@continueWith Tasks.whenAll(fetchAlbumTasks).continueWith allTasks@ {
return@allTasks albums as List<Album>
}
}
}
However I would like this operation to return type Task<List<Album>>
to keep the interface clean.