Skip to content

Commit 3efe865

Browse files
committed
fix disposing in scheduled tasks
1 parent 607602f commit 3efe865

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/scheduling/schedulers.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fun Disposable.disposingOneShotDelayedTask(name: String, delay: Long, block: ()
349349
consider this:
350350
calling disposingOneShotDelayedTask on a Disposable ,lets say a project service. and we would just register
351351
a child disposable on the project service to cancel the task.
352-
if the project is closed before the task is executed the parent disposable, the service, will be disposed with all its children
352+
if the project is closed before the task is executed, the parent disposable, the service, will be disposed with all its children
353353
and the task will be canceled.
354354
but if the task did execute and the project service was not disposed yet, we are left with a disposable child that will be disposed
355355
only when the service is disposed.
@@ -359,14 +359,14 @@ fun Disposable.disposingOneShotDelayedTask(name: String, delay: Long, block: ()
359359
the solution:
360360
calling disposingOneShotDelayedTask on a Disposable project service. the parent.
361361
we create here a new disposable,the child, register it as child of the parent.
362-
register the task on the child disposable and in disposingOneShotDelayedTask0 we register a child for the child.
362+
register the task on the child disposable and in disposingOneShotDelayedTaskImpl we register a child for the child.
363363
if the parent is disposed before the task is executed, the first child will be disposed, its child will be disposed and the task
364364
will be canceled.
365365
if the task executed and completed, the task itself disposes the first child, which will dispose its child. and now the parent
366366
doesn't have a leftover child.
367367
368-
Notice that we execute disposingOneShotDelayedTask0 on the child disposable, its private and should only be used internally.
369-
in disposingOneShotDelayedTask0 when the task completes it disposes this in the finally block.
368+
Notice that we execute disposingOneShotDelayedTaskImpl on the child disposable, its private and should only be used internally.
369+
in disposingOneShotDelayedTaskImpl when the task completes it disposes 'this' in the finally block.
370370
see unit tests:
371371
testDisposingOneShotDelayedTaskParentDisposableHasNoChildren
372372
testDisposingOneShotDelayedTaskCanceledParentDisposableHasNoChildren

src/main/kotlin/org/digma/intellij/plugin/ui/notificationcenter/NoInsightsYetNotification.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
1515
import java.time.Instant
1616
import kotlin.time.Duration.Companion.minutes
1717

18-
18+
//parentDisposable is the service
1919
fun startNoInsightsYetNotificationTimer(parentDisposable: Disposable) {
2020

2121
if (service<PersistenceService>().isFirstInsightReceived()) {
@@ -44,9 +44,7 @@ private fun scheduleShowNotification(parentDisposable: Disposable, firstConnecti
4444
firstConnectionTime
4545
)
4646

47-
val disposable = Disposer.newDisposable()
48-
Disposer.register(parentDisposable, disposable)
49-
disposable.disposingOneShotDelayedTask("NoInsightsYetNotificationTimer.showNoInsightsYetNotification", 30.minutes.inWholeMilliseconds) {
47+
parentDisposable.disposingOneShotDelayedTask("NoInsightsYetNotificationTimer.showNoInsightsYetNotification", 30.minutes.inWholeMilliseconds) {
5048
if (!service<PersistenceService>().isFirstInsightReceived()) {
5149
Log.log(AppNotificationCenter.logger::info, "in NoInsightsYetNotificationTimer, showing notification")
5250
showNoInsightsYetNotification()

0 commit comments

Comments
 (0)