com.pubnub.api.endpoints.remoteaction.MappingRemoteAction.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-kotlin Show documentation
Show all versions of pubnub-kotlin Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of
broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter
second!
package com.pubnub.api.endpoints.remoteaction
import com.pubnub.api.enums.PNOperationType
import com.pubnub.api.models.consumer.PNStatus
class MappingRemoteAction(private val remoteAction: ExtendedRemoteAction, private val function: (T) -> U) :
ExtendedRemoteAction {
override fun operationType(): PNOperationType {
return remoteAction.operationType()
}
override fun retry() {
remoteAction.retry()
}
override fun sync(): U? = remoteAction.sync()?.let { function(it) }
override fun silentCancel() {
remoteAction.silentCancel()
}
override fun async(callback: (result: U?, status: PNStatus) -> Unit) {
remoteAction.async { r, s -> callback(r?.let(function), s) }
}
}
fun ExtendedRemoteAction.map(function: (T) -> U): ExtendedRemoteAction {
return MappingRemoteAction(this, function)
}