I have a progress notifier class for download prog...
# coroutines
d
I have a progress notifier class for download progress implemented as an Actor, in Android, if too many notifications are send the UI hangs, so I need to filter the messages the downloader sends through the actor to update the notification, say every second, and only when the percent downloaded changes. What's the best way to do this with channels (I need to download pieces of the file concurrently)? This is my current code (but I think it's wrong since the delay will just hold up the downloading progress...):
Copy code
GlobalScope.actor<InstallState>(capacity = Channel.CONFLATED) {
		val notification = progressNotifierFactory(
				fileName.hashCode(),
				R.drawable.icon,
				name
		)

		var downloadSize = 0L

		channel.consumeEach { msg ->
			when (msg) {
				is InstallState.Downloading ->
					notification.update(R.string.notif_file_downloading, null, msg.totalMb)
							.also { downloadSize = msg.totalMb }

				is InstallState.UpdateDownloadProgress -> {
					i { "Notifying progress: ${msg.currPercentage}" }
					delay(500)
					notification.update(
							R.string.notif_file_downloading,
							msg.currPercentage,
							downloadSize
					)
				}

				is InstallState.Failed ->
					notification.update(R.string.notif_file_download_failed, 0)
			}
		}
	}