louiscad
08/04/2021, 2:15 PMval stuff1: Stuff
val stuff2: Something
val nameOfWhatever: String
withLoading("Doing something long") {
stuff1 = step { getStuff(someInput) }
stuff2 = step { getSomething(stuff1) }
nameOfWhatever = step { fetchThing(someInput, stuff2) }
}
In the snippet above, I'd like withLoading
to know how many calls to step
there are in the lambda it's been passed, so it can show somewhere "Step 1/3" while getStuff(…)
is executing.
Currently, it's impossible to do, and having the desired result requires quite a bit of unsafe boilerplate, unsafe in that if I do a mistake like starting with step 3 instead of 1, the compiler won't spot it.
Of course, there'd be concerns about having conditionally called step { … }
calls, and possible nesting, plus one might want to provide some info to step
to show on a UI what the next steps are (e.g. their title, some icon…)ephemient
08/04/2021, 10:06 PMlouiscad
08/05/2021, 6:53 AMstep { … }
are suspending and where I want step
to return the value of the lambda directly, to avoid needing indirection.louiscad
08/05/2021, 6:54 AMephemient
08/05/2021, 7:56 AMephemient
08/05/2021, 7:58 AMlouiscad
08/05/2021, 7:59 AMlouiscad
08/05/2021, 8:00 AM