I'm trying to model a 'lazy suspend' task.
For the moment, it's encoded as:
val task = scope.async {
foo()
}
suspend fun bar() {
// All calls require the task to be over,
// however only the first one(s) will really suspend,
// since it will be ready for the others
val foo = task.await()
doSomething(foo)
}
The problem is that this requires a
scope
to be available when the task is instantiated. Since I do not care whether the task starts when it is instantiated or when the first call to
bar
is made, is there a way to adapt this pattern without requiring the
scope
?