commonMain.io.realm.kotlin.mongodb.internal.FunctionsImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of library-sync Show documentation
Show all versions of library-sync Show documentation
Sync Library code for Realm Kotlin. This artifact is not supposed to be consumed directly, but through 'io.realm.kotlin:gradle-plugin:1.6.2' instead.
/*
* Copyright 2022 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.realm.kotlin.mongodb.internal
import io.realm.kotlin.internal.interop.RealmInterop
import io.realm.kotlin.internal.util.use
import io.realm.kotlin.mongodb.Functions
import kotlinx.coroutines.channels.Channel
@PublishedApi
internal class FunctionsImpl(
override val app: AppImpl,
override val user: UserImpl
) : Functions {
@PublishedApi
internal suspend fun callInternal(
name: String,
serializedEjsonArgs: String
): String = Channel>(1).use { channel ->
RealmInterop.realm_app_call_function(
app = app.nativePointer,
user = user.nativePointer,
name = name,
serializedEjsonArgs = serializedEjsonArgs,
callback = channelResultCallback(channel) { ejsonEncodedObject: String ->
// First we decode from ejson -> BsonValue
// then from BsonValue -> T
ejsonEncodedObject
}
)
return channel.receive().getOrThrow()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy