<@U5UU34LPK> Coroutines remove callback hells, and...
# announcements
l
@karelpeeters Coroutines remove callback hells, and allow for easy thread or thread pool switching. They allow to write asynchronous code in a sequential style. Best Kotlin feature IMHO
👍 3
k
I want to learn them, but i'm still waiting for a use case.
l
What are you working on?
k
A custom language that compiles down to AVR bytecode right now 🙂
l
I mean, in Kotlin, what do you do with Kotlin? Unless you use Kotlin for that thing and do only that?
k
Well I only use Kotlin for hobby projects and that's my current one.
l
Coroutines also allow for easy cancellation, and easy parallelism
o
For some time I have an idea of coroutine-based parser, but didn’t have time to explore it. Since coroutines are state machines, and parsers are state machines… well, something can be interesting here 🙂
👍 1
k
That's an interesting idea, because for the recursive descent parser I'm using recursion, but it would be neat if that can be done with coroutines.
o
My idea was to have multiple coroutines running simultaneously, representing each possible parse “path”, and then each that fails to continue just stops working and in the end only one finishes. Or none, which means syntax error and the last one (longest) will report error. Or many, so there is ambiguity. Parsing coroutines can even recover each by itself and then some algorithm would choose best recover and continue from there.
Suspending function would be obviously
lexer.nextToken()