by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
elyphas
@elyphas
well, rowRepository is my trait :P
I am trying event.dump("0") :)
Piotr Gawryś
@Avasil
ahh, it needs to be in onEvent then val onEvent: Observable[Either[String,(QryRow, EventsDoobieResult)]] = event.dump("O").mapEval(...)
yes
elyphas
@elyphas
sorry, :)
elyphas
@elyphas
@Avasil : 0: 0 --> Some(HashMap(id_comparativo -> JsonString(2256-2020-ADQ2), unid_med_pres -> JsonString(), cantidad -> JsonInt(9), unidad_medida -> JsonString(CAJA), descripcion -> JsonString(LAPICERO AZUL ), cve_articulo -> JsonString(021.101.8983), presentation -> JsonInt(0), description -> JsonString(LAPICERO TINTA AZUL ), programa -> JsonString(INSABI)))
But I have other thing:
2020.09.19 17:05:49 [INFO] covenant.core.DefaultLogHandler.logRequest:13:16 - --> Api.eventRow(Row(2256-2020-ADQ2,INSABI,0,021.101.8983,,Some(1),Some(9),Some(),Some(),Some(),false,1),InsertDoobie). BrowserConsoleWriter.scala:22:17

2020.09.19 17:05:49 [INFO] covenant.core.DefaultLogHandler.logRequest:15:18 - <-- Api.eventRow(Row(2256-2020-ADQ2,INSABI,0,021.101.8983,,Some(1),Some(9),Some(),Some(),Some(),false,1),InsertDoobie) = Success(Right((QryRow(2256-2020-ADQ2,2,INSABI,021.101.8983,LAPICERO TINTA AZUL ,CAJA,Some(0),None,21101,21101: MATERIALES Y UTILES DE OFICINA ,9,None,None,None,Some(16),None,None,None),FoundDoobie(Se encontro)))). Took 0.054s
is triggering twice, but none error happens
but now I see I need to search another place.
elyphas
@elyphas
not ,is good is the response :P
@Avasil , thank you very much.
now I am sure the problem is in another place.
Piotr Gawryś
@Avasil
Cool, good luck! I'm going to sleep soon but I'm happy to answer more questions in the morning if there are any
elyphas
@elyphas
good night, I think, :) here is 5:20 pm.
elyphas
@elyphas

@Avasil ; Thank you very much, just found the problem, it was here:

grid.hdlChangingValue.debounce(800 milliseconds)                                      
        .filter { case (fld, value@_) => fld == "descripcion" }    // I added this                             
        .filter { case (fld, JsonString(txt)) => fld == "descripcion" && txt.length > 4}          
        .onErrorRecoverWith {   // I added this                                                                  
            case ex =>                                                                            
                println("An error throw when processing hdlChangingValue on description_item line 304 FrmLstItems")    
                println(ex.getMessage + " -- " + ex.getLocalizedMessage + " -- " + ex.getCause)                          
                Observable(("", JsonString("")))                                                                         
        }                                                                                            
        .map { case (fld@_, JsonString(txt)) =>                                                   
              println(s"Vamos a buscar el articulo $txt")                                         
              ("ftsArticulo", "descripcion", txt)                                                 
        }

I needed to add a filter and a onErrorRecoverWith

Piotr Gawryś
@Avasil
Great to see that you have managed to solve the problem!
Note that onErrorRecoverWith doesn't work on "element-level", it replaces the original source that failed (grid.hdlChangingValue) with a backup (Observable(("", JsonString(""))) and the stream ends on this element. Not sure if that's what you need
elyphas
@elyphas
@Avasil ; it was the first thing came to my mind, any better idea?
I don't know most of the philosophy of functional reactive I am trying to introduce all I can do without making my advance worse. :)
Piotr Gawryś
@Avasil
There are at least two options if you want the source to keep going after failure:
  • handle error in the operator that causes it (e.g. if grid.hdlChangingValue fails in mapEval, you can handle it inside mapEval)
  • if the source can be restarted, do
    onErrorRecoverWith {
    case ex =>
    // signal error
    grid.hdlChangingValue.debounce(800 milliseconds).(....) // ideally you just call onErrorRecover earlier
    }
elyphas
@elyphas
@Avasil ; ah thank you, :)
@Avasil ; I need to nested all the code inside the onErrorRecoverWith?
elyphas
@elyphas
like a recursion
Piotr Gawryś
@Avasil

No you could do

val source = grid.hdlChangingValue.debounce(800 milliseconds).filter.filter

source.onErrorRecoverWith(ex => source)

or sth like

grid.hdlChangingValue.onErrorRecoverWith(ex => grid.hdlChangingValue).debounce(800 milliseconds).filter.filter
Or maybe even doOnError(signalError).onErrorRestartUnlimited instead of onErrorRecoverWith
elyphas
@elyphas
cool

Or maybe even doOnError(signalError).onErrorRestartUnlimited instead of onErrorRecoverWith

what are the difference?

Piotr Gawryś
@Avasil
Semantically, it's the same
elyphas
@elyphas
by the way finally I can see a little bit of the great of this.

Semantically, it's the same

ah ok,

It was hard for me, I need more reactive functional code to introduce in my app, so I can advance faster, this because I fall in OO almost always. :)
thank you, You made me do I large jump,
Piotr Gawryś
@Avasil
I'm happy to hear it! I hope to create some Observable educational resources this year
elyphas
@elyphas
great
Pau Alarcón
@paualarco
hello! is there any method to convert a Task[List[T]] into an Observable[T]?
normally I do: val ob: Observable[Int] = Observable.from(Task.now(List(1, 2, 3))).flatMap(Observable.fromIterable)
but might be nicer to do it straight away like Task.now(List(1, 2, 3)).flatMapMany(_)
Piotr Gawryś
@Avasil

There's no dependency on Observable inmonix-eval and there are no extension methods for Task in monix-reactive so there isn't

You could also do task.flatMap(list => Observable.fromIterable(list).op1.op2.op3) if you run Observable to Task

Pau Alarcón
@paualarco
that makes sense, thanks :)
Glen Marchesani
@fizzy33
is there a simple pattern given an existing left Observable[A] to concatenate with the right Observable[A] that is built using the the last A of the left ???
so
val left: Observable[A] = ...
def right(a: A): Observable[A] = ...
and I pseudo codedly want
left ++ right(left.last)
Glen Marchesani
@fizzy33
perhaps
left ++ left.last.flatMap(right)
Glen Marchesani
@fizzy33
that did thanks everyone (sometimes all one needs is a rubber ducky to talk to)
Piotr Gawryś
@Avasil

I think we could use an operator for that, it comes up from time to time. Something like zipWithPrevious from fs2, and/or prefixAndTail from Akka Streams

Note that

left ++ left.last.flatMap(right)

will run left twice unless it's hot Observable like

left.publishSelector { hot =>
  hot ++ hot.last.flatMap(right)
}
Glen Marchesani
@fizzy33
roger that (and yes left is hot)
neat to know the publishSelector usage, I had stared at that wondering when I would use it :-)
Glen Marchesani
@fizzy33
as I was wondering how on earth I would optimize that for the cold observable case...
Piotr Gawryś
@Avasil
I like publishSelector a lot but it might be a good idea to think about adding more discoverable alias :D
Glen Marchesani
@fizzy33
I like it a lot too now :-)
elyphas
@elyphas
Hi, How can I know when all my three observer completed its jobs?
for this code:
val eventComparative = PublishSubject[String]()
val getMinimosRetensionISR = eventComparative.dump("0").mapEval { case idComparative =>
val getProcess =  eventComparative.dump("0").mapEval { case idComparative =>
val getComparativo =  eventComparative.dump("0").mapEval { case idComparative =>
     val chekar = new Observer[Either[String, String]] {     
          def onNext(elem: Either[String, String]): Future[Ack] = {    
                  println("En el observer del get Comparative")    
                  println(elem)    
                  Continue    
          }                                                                                                                                                                 
          def onError(ex: Throwable): Unit = { alert(ex.printStackTrace.toString) }                                                                                         
          def onComplete(): Unit = println("O completed on Get Comparative's Data")                                                                                         
      }                                                                                                                                                                     

  getMinimosRetensionISR.subscribe { chekar }                                                                                                                               
  getProcess.subscribe{chekar}                                                                                                                                              
  getComparativo.subscribe{chekar}