BlockingMessageGateway
An environment for observing and awaiting specific messages. Usage example:
import pl.novelpay.client.sdk.interceptor.ClientInterceptor
import pl.novelpay.client.sdk.util.BlockingMessageGateway
import pl.novelpay.protocol.shared.message.DomainMessage
import pl.novelpay.retailer.RetailerResponse
val observer = BlockingMessageGateway()
val communicationInterface: RetailerCommunicationInterface = TODO("Stands for instance of SDK")
/**
* In place of sending, specify mid-upper bound of message
* Otherwise, for example if you'll specify [RetailerResponse], all responses will met type-chek
* therefore every response message will unlock the this suspension (unwanted unlock on
* every intermediate message).
*/
observer.sendBlocking<CardAcquisitionResponse> {
communicationInterface.sendCardAcquisitionRequest(CardAcquisitionRequestArguments())
}
ClientInterceptor { domainMessage: DomainMessage ->
observer.onMessage(domainMessage)
// Or your default non-blocking logic of domainMessage handling
?: Result.failure(IllegalArgumentException("Message is wrong"))
}Content copied to clipboard
Functions
Link copied to clipboard
Subclasses should call this method once new DomainMessage arrives in pl.novelpay.client.sdk.interceptor.ClientInterceptor
Link copied to clipboard
inline fun <Message : DomainMessage> putDeferredOrThrow(deferred: CompletableDeferred<Message>): Nothing?
Link copied to clipboard
inline suspend fun <Message : DomainMessage> sendBlocking(sendingCoroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO), timeoutMillis: Long = 60000, crossinline sendMessage: suspend () -> Unit): Message
Executes a message-sending action and suspends until a message of the specified type Message is received.