fixed streaming crash caused by incompatible forEach call

This commit is contained in:
Mariotaku Lee 2017-03-20 21:54:14 +08:00
parent c534e82f80
commit 6618bfccc4
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 10 additions and 2 deletions

View File

@ -76,7 +76,12 @@ class StreamingService : BaseService() {
}
override fun onDestroy() {
submittedTasks.values.forEach { it.cancel() }
submittedTasks.forEach {
// NOTE: IMPORTANT!!! Before Nougat, forEach { k, v -> } will crash because referenced
// BiConsumer, which is introduced in Java 8
val (_, v) = it
v.cancel()
}
threadPoolExecutor.shutdown()
submittedTasks.clear()
removeNotification()
@ -139,7 +144,10 @@ class StreamingService : BaseService() {
if (enabledAccounts.isEmpty()) return false
// Remove all disabled instances
submittedTasks.forEach { k, v ->
submittedTasks.forEach {
// NOTE: IMPORTANT!!! Before Nougat, forEach { k, v -> } will crash because referenced
// BiConsumer, which is introduced in Java 8
val (k, v) = it
if (enabledAccounts.none { k == it.key } && !v.cancelled) {
v.cancel()
}