From 25760fa2d066a23e7fc72747f59c964e76ed0889 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 24 Dec 2018 17:41:08 -0500 Subject: Avoid events for duplicate cancellations --- .../kotlin/com/pitchedapps/frost/services/NotificationService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index ea215b5c..40a78b04 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -57,6 +57,8 @@ class NotificationService : JobService(), CoroutineScope { } private fun prepareFinish(abrupt: Boolean) { + if (job.isCancelled) + return val time = System.currentTimeMillis() - startTime L.i { "Notification service has ${if (abrupt) "finished abruptly" else "finished"} in $time ms" } frostEvent( @@ -75,7 +77,8 @@ class NotificationService : JobService(), CoroutineScope { try { async { sendNotifications(params) }.await() } finally { - prepareFinish(false) + if (!job.isCancelled) + prepareFinish(false) jobFinished(params, false) } } -- cgit v1.2.3