I'm trying to do something like this with Kotlin Coroutines (this is pseudocode):
suspend fun myFunction() {
if (job.isActive) {
job.join()
return job.result
} else {
job.start()
job.join()
return job.result
}
}
Basically, to have a job that executes some code and returns a value. Then the function uses that job. If the job is not started, it executes it and returns its results. If the job is already started, it waits till its finished and returns its result.
But not sure how to approach this. Any suggestion?