fun DownloadTask.spChannel(): Channel<DownloadProgress>
This method will create a Channel to represents a single download task's progress. In this way, the DownloadTask is a producer and the returned Channel can be consumed by specific consumer.
Note: This method must be invoked after the DownloadTask is started, otherwise, there is no any effect. For example:
val task = DownloadTask.Builder().build()
task.enqueue() { task, cause, realCause -> }
val progressChannel = task.spChannel()
runBlocking {
for (dp in progressChannel) {
// show progress
}
}