https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

louiscad

03/09/2018, 8:22 AM
Hi, just had an idea: What about showing an icon in the gutter or a "bar" on the left in the IDE to show where a higher order suspend function starts (e.g.
launch
and any other function whose lambda is a
suspend
one)? This could be a play sign with the curve, similar to the arrow with the curve we have for suspension points. This would help knowing where suspend calls are allowed in current code, helping to see potentially unneeded coroutines launches
o

orangy

03/09/2018, 8:31 AM
I like the idea, it could indeed show relevant information. However I’m afraid so many markers would pollute gutter, it is already barely usable in a highly suspendable code… May be an inspection would be better? Like, if there are no suspend calls inside
launch
body… Or may be less prominent in-editor markers…
l

louiscad

03/09/2018, 9:05 AM
Do you have an IDE screenshot of example of "highly suspendable code"? I'm personally not bothered with the suspend marks (but disabled VCS changes info in the gutter years ago), they're useful to me and I don't experience gutter pollution at the moment. An inspection could be nice too, but I fear it could have false positives between suspend lambdas from APIs you can't change and
launch
,
async
,
runBlocking
plus custom coroutines launch utilities (e.g.
launchInUi
that checks Android UI thread, and starts undispatched). I mean it could flag unused suspension ability in
launch
or a custom coroutine launcher function, but would also flag a suspend listener lambda from a third party lib. Also, one may launch a coroutine just to make the code run in a certain dispatcher. On the other hand, a gutter icon (that may have its design tweaked if too invasive, alpha FTW) would only be informative, similar to lambda receiver type hints, but less invasive (personally dislike their verbosity, I just find them good for learning)
e

elizarov

03/09/2018, 9:30 AM
For launch and async (that actually start new coroutine, working concurrently with the code around it), I’d use something even more visually prominent, like a different background for a whole block and warn (suggest to refactor) code that nests such blocks.
4
d

dave08

03/09/2018, 10:40 AM
And, or maybe differently styled code folding lines
🤔 1
e

elizarov

03/09/2018, 10:43 AM
d

dave08

03/09/2018, 10:44 AM
That little plus minus in the gutter also delimits the function span, there could be a specially styles one for launches that might even fold differently (with relevant coroutine info) maybe in addition to the different background color...
8 Views