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
Use kotlinx-coroutines for UI launcher #712
Conversation
private suspend fun setProgress(splash: SplashScreen, progress: Int) { | ||
splash.setProgress(progress) | ||
// Allow UI updates | ||
yield() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FSchumacher , this enables to make a brief pause in the execution of the current coroutine, and it immediately schedules the continuation. That allows Swing EDT to update the UI.
The code in startGuiPartTwo
looks sequential, however, in practice, it is split into a sequence of chunks.
withContext(Dispatchers.Default) { | ||
f = File(testFile) | ||
log.info("Loading file: {}", f) | ||
FileServer.getFileServer().setBaseForScript(f) | ||
tree = SaveService.loadTree(f) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what switching between "regular thread pool" and "Swing event dispatcher" would look like. The code within withContext(Dispatchers.Default)
is executed outside of the EDT, and then the execution moves back to the EDT.
Codecov Report
@@ Coverage Diff @@
## master #712 +/- ##
=========================================
Coverage 55.23% 55.23%
- Complexity 10382 10383 +1
=========================================
Files 1061 1062 +1
Lines 65763 65760 -3
Branches 7530 7533 +3
=========================================
+ Hits 36322 36324 +2
+ Misses 26841 26837 -4
+ Partials 2600 2599 -1
Continue to review full report at Codecov.
|
@pmouawad , @FSchumacher , team. do you have any thoughts/comments? I think this is pretty much mergeable, except I would like to make I am fine if this is merged after 5.5 release, however, including the change in 5.5 might work as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Description
This PR moves
startGui
fromclass JMeter
to another class.Motivation and Context
a) It is nice to factor UI from non-UI code
b) Current code fails to update progress during "GUI startup". The reason is that all the contents of
startGui
is running in a singleRunnable
, so Swing has no way to break in-between and render progress updates.See https://bz.apache.org/bugzilla/show_bug.cgi?id=66044#c5
Coroutines enable an easy-to-maintain approach for splitting long UI methods into chunks.
In this case, I used
yield()
right aftersetProgress
, so we give room for the Swing event dispatcher thread to update the UI.See also https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md
Checklist: