In this exported class with a `suspend fun example...
# javascript
e
In this exported class with a
suspend fun example
, what's the role of the
suspendBridge
?
Copy code
class TestExport {
  *example_1u0ivn_k$($completion) {
    println('example');
    return Unit_instance;
  }
  example() {
    return promisify(($completion) => this.example_1u0ivn_k$($completion));
  }
  *example$suspendBridge_5xvqmk_k$($completion) {
    if (this.example === protoOf(TestExport).example)
      yield* this.example_1u0ivn_k$($completion);
    else
      yield* await_0(this.example(), $completion);
    return Unit_instance;
  }
}
PrepareSuspendFunctionsForExportLowering
has a brief explanation in its KDoc. Although I don't completely understand what > This function is used on the call side means in this context as that
*example$suspendBridge_5xvqmk_k$
function is never called in the bundle.
a
So, the idea is the following: each time you cal the
example
function we replace the call with the call of the
suspendBridge
, so that if the method is overriden from TypeScript we would call typescript version with
await
, otherwise just Kotlin suspend function. We actually can remove such bridge for final classes if we find a way to declare prevent extending them on the TypeScript level
gratitude thank you 1
e
> We actually can remove such bridge for final classes if we find a way to declare prevent extending them on the TypeScript level That's exactly what I was wondering. But in this case specifically, even if I extend that class from TS, how do you call
*example$suspendBridge_5xvqmk_k$
? Maybe this specific case is "strange" or I just don't have a proper example, but the fact it's never called in the bundle makes me think the only "rule" could be: is the class
open
or not?
a
True, but unfortunately there is no such thing in TS, so. even class is final in Kotlin doesn't prevent to extend it in TS (at least right now, until we found some idea how to do this without another
__doNotUseItOrImplementIt
property)
e
True, but let's say I extend that class from TS, you won't call that bridge method anyway. At least not from the code I see currently. The method that's called is always
example
, never the bridge. Probably I'm missing the bigger picture.
👀 1
pepenotingfast 1