All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pubnub.api.endpoints.remoteaction.MappingRemoteAction.kt Maven / Gradle / Ivy

Go to download

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!

There is a newer version: 10.2.0
Show newest version
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)
}