Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chat.destroy() method, TimerManager class #66

Merged
merged 9 commits into from
Sep 6, 2024
Merged

Conversation

wkal-pubnub
Copy link
Contributor

TimerManager is used to group PlatformTimers and let us cancel them when destroying Chat.

}

// this should run 3 times
// let's also try to start it from a background thread to test if cancellation works in that case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you check if cancellation works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not cancelled by timerManager.destroy() then counter2.value will be > 3
at the end of the test we check if it's exactly 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting cancellation be executed like this:

        val runPeriodically1: PlatformTimer
        withContext(Dispatchers.Default) {
            runPeriodically1 = timerManager.runPeriodically(0.5.seconds) {
                counter2.incrementAndGet()
            }
            
        }
        runPeriodically1.cancel()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add one more test to check cancellation with cancel()

@wkal-pubnub
Copy link
Contributor Author

looks like test was flaky, merging

@wkal-pubnub wkal-pubnub merged commit 82462a3 into master Sep 6, 2024
3 of 5 checks passed
@wkal-pubnub wkal-pubnub deleted the wkal/shutdown branch September 6, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants