georgi
07/14/2023, 11:01 PM@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
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 🙏georgi
07/15/2023, 8:32 AMexternal
definition seems to be wrong. PubSub defines exists
as
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
fun exists(): Promise<Array<Boolean>>
...
if (topic.exists().await().first()) {
...
}
and now the Promise resolves correctly.