Calling a (dynamic) JS function returning a Promise from Kotlin

Viewed 145

I'm new to Kotlin and I'm trying to perform the equivalent of this JS snippet from Kotlin/JS. myFunction is supposed to return a Promise of Something:

myFunction()
    .then(onSuccess, onFailure);

function onSuccess(something) {
    console.log(something);
}

function onFailure() {
    console.log('Error!');
}

How would you do that from Kotlin?

1 Answers

I suppose that's obvious for experienced Kotlin Programmers, but here's how I solved it:

        myFunction().then {
            something -> onSuccess(something)
        }.catch {
            onFailure()
        }
Related