One of the more interesting use cases for coroutin...
# coroutines
g
One of the more interesting use cases for coroutines is factoring out use of a bad concurrent API inner-platform (en.wikipedia.org/wiki/Inner-platform_effect) in java. On our code base, me, being over-enthusiastic and dumb, created a
public static T await(Future<T> future)
that used
Toolkit.enter/exitNestedEventLoop
in java to create what is a kind of stackful coroutine. There are a number of problems with this strategy and I do not recomend it. But the problem now is that we have a whole bunch of java code, written in an imperative style, that was accidentally using coroutines. Retrofitting it to use
CompeltableFuture.whenComplete
properly would be a fairly serious time investment. Its easier for us to just
ctrl
+
alt
+
k
the set of ~5 classes, and throw
suspend
infront of the methods where appropriate. Then uses of my custom
public static T await(Future<T> future)
with kotlinx's extension functions.