This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val eventDocument = PublishSubject[(Inputs, EventsDoobieWillDo)]() | |
//Old, New | |
val onEventDocument: Observable[Either[String, (Inputs, Inputs, EventsDoobieResult)]] = | |
eventDocument.dump("onEventDocument:").mapEval { case (oldItem, event) => | |
Task.suspend { | |
Task.fromFuture { | |
val payload = Pickle.intoBytes[(Inputs, EventsDoobieWillDo)]((oldItem, event)) | |
val endPoint = event match { | |
case InsertDoobie => "saveInputs" | |
case UpdateDoobie => "saveInputs" | |
case FindDoobie => "getInputs" | |
case DeleteDoobie => "deleteInputs" | |
} | |
val respondWS = WSMyCelium.ws.send(endPoint :: Nil, payload, SendType.WhenConnected, 30 seconds) | |
respondWS.failed.foreach(println) | |
respondWS | |
}.redeem ( | |
err => Left(err.getMessage), | |
{ | |
case Right(value) => | |
val unpickle = Unpickle[Either[String, (Inputs, EventsDoobieResult)]].fromBytes(value) | |
unpickle match { | |
case Right((newItem, eventReturn)) => | |
println(s"Regreso de $event") | |
println(s"Hizo un $eventReturn") | |
val checarEvent = if (eventReturn == DeletedDoobie) FoundDoobie() else eventReturn | |
Right((oldItem, newItem, checarEvent)) | |
//Right((oldItem, newItem, eventReturn)) | |
case Left(errors) => Left(errors) | |
} | |
case Left(failure) => Left(failure) | |
} | |
) | |
} | |
} | |
val processSideEffects = onEventDocument | |
.dump("Changos en el processSideEffects") | |
.map { ver => | |
println("Changos en el processSideEfects :") | |
println(s"Lo que va ha imprimir: $ver") | |
ver match { | |
case Right((oldItem, newItem, event)) => | |
event match { | |
case FoundDoobie(x) => x | |
case SavedDoobie(x) => x | |
case DeletedDoobie(x) => x | |
case NotFoundDoobie(x) => x | |
case ErrorDoobie(x) => x | |
} | |
case Left(error) => error | |
} | |
} | |
val obsIsNew = onEventDocument.map { | |
case Right((oldItem, newItem, event)) => | |
println("En el obsIsNew ****************") | |
event match { | |
case SavedDoobie(_) | FoundDoobie(_) => false | |
case DeletedDoobie(_) => true | |
case NotFoundDoobie(_) | ErrorDoobie(_) => true | |
} | |
case Left(error) => false | |
} | |
val obsMainItem = onEventDocument.map { | |
case Right((oldItem, newItem, event)) => | |
println("En el obsMainItem ****************") | |
event match { | |
case NotFoundDoobie(msg) => oldItem | |
case _ => newItem | |
} | |
case Left(error) => Inputs() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment