:wave: Heya! I'm working with Google PubSub and have the following external declarations ```@file:Js...
g
👋 Heya! I'm working with Google PubSub and have the following external declarations
Copy code
@file:JsModule("@google-cloud/pubsub")
@file:JsNonModule

@JsName("PubSub")
external class GoogleCloudPubSub {
    fun topic(name: String): GoogleCloudPubSubTopic
}

external class GoogleCloudPubSubTopic {
    fun exists(): Promise<Boolean>
}
Elsewhere I'm using this as
Copy code
launch {
    val topic = GoogleCloudPubSub().topic("blah-blah")
    val result = topic.exists().await()
    println(result)
    if (result) { println("Exists") } else { println("Doesn't exist") }
}
The first print correctly shows
true
|
false
for the result of
exists()
. However, the
if
statement never runs even if
result
is
true
- if I do something like this
val result = topic.exists().await().toString()._toBoolean_()
it works fine. Any ideas as to why it's happening? Thanks in advance 🙏
2
I think I've found the problem. My
external
definition seems to be wrong. PubSub defines
exists
as
Copy code
exists(): Promise<ExistsResponse>;
export type ExistsResponse = [boolean];
and in my case I interfaced it as
fun exists(): Promise<Boolean>
which I think was triggering the truthy Promise behaviour of always having a "true" response. I changed my code to
Copy code
fun exists(): Promise<Array<Boolean>>
...
if (topic.exists().await().first()) {
    ...
}
and now the Promise resolves correctly.
🎉 1
1