Coroutine Context access from non suspendable function

Hi, Is there any way to access coroutine context from non suspendable function that called from suspendable function.

Here is an example

We have a java interface

interface OldNFancyJavaInterface {
    function String coolLegacyFunctionFromJava(String exampleInputValue);

We have a Kotlin class which extends this interface

class NewNFancyKotlinClass : OldNFancyJavaInterface {
    override fun coolLegacyFunctionFromJava(exampleInputValue: String): String {
        /* this function should run only from within coroutine otherwise throw an exception
         * so if we could do something like */
        val context = coroutineContext() ?: throw OopsNoContextException()
        // It would be cool

and here it is on call side

suspend fun noExceptionCall() {
    val result = whereDidHeGotThisVariable.coolLegacyFunctionFromJava()

fun exceptionCall() {
    val result = whereDidHeGotThisVariable.coolLegacyFunctionFromJava()

And mainly there is no possibility to pass context as a constructor parameter cause for example this class should have no arguments to work with java ServiceLoader
If there is no opportunity to check from what context we are run maybe we should add one?

What would you do with such a feature if it existed? What would you do with the coroutine context?

You can launch coroutines from non-suspending code and then use the coroutineContext provided.

fun myCoolMethodStartsACoroutine() {
    val job = GlobalScope.launch {