Questions tagged [monix]

Monix is a library providing asynchronous programming facilities for Scala and Scala.js.

94 questions
3
votes
2 answers

Convert List[Task[List[A]]] to Task[List[A]]

How to convert List[Task[List[Header]]] type to Task[List[Header]] in scala . I have a method which returns Task[List[Header]] and calling dor multiple times it becomes List[Task[List[Header]]]
Sumeet Kumar Yadav
  • 11,912
  • 6
  • 43
  • 80
3
votes
2 answers

Monix Task.sleep and single thread execution

I am trying to comprehend Task scheduling principles in Monix. The following code (source: https://slides.com/avasil/fp-concurrency-scalamatsuri2019#/4/3) produces only '1's, as expected. val s1: Scheduler = Scheduler( …
Kamil Kloch
  • 333
  • 1
  • 9
2
votes
0 answers

How to create an Observable from a non thread-safe iterator?

I’m trying to create an Observable from an iterator that is not thread safe. I’m creating the iterator using Observable.resource, and then creating an Observable around this iterator using Observable.fromIterator. I then use…
WilQu
  • 7,131
  • 6
  • 30
  • 38
2
votes
1 answer

Error Handling on Monix parallel tasks (using parMap)

I am trying to use monix to do parallelize certain operations and then perform error handling Lets say I am trying to parse and validate a couple of objects like this def parseAndValidateX(x: X) Task[X] and def parseAndValidateY(y: Y):…
Arunav Sanyal
  • 1,708
  • 1
  • 16
  • 36
2
votes
0 answers

How to add fixed delay for each Task in monix without building up delay

I'm consuming messages from kafka using monix. I want to process the message 10 sec after the message is read from the topic. This delay of 10 sec minute shouldn't block reading more messages. I've tried to test this behaviour using the following…
N A
  • 831
  • 2
  • 8
  • 28
2
votes
1 answer

Different monads in for comprehension

I have below code def processInfoAndReturnResponse(input: Input]): EitherT[Future, CustomException, A] = ??? def sendMessage(message: A): monix.eval.Task[Boolean] = ??? def anotherMethod(message: Input): Future[Either[CustomException, Unit]]=…
ApprenticeWST
  • 117
  • 1
  • 7
2
votes
1 answer

How can I run parSequenceUnordered of Monix, and handle the results of each task?

I am currently working on implementing client-side http requests to an API, and decided to explore sttp & monix for this task. As I am new to Monix, I am still not sure how to run tasks and retrieve their results. My objective is to have a sequence…
alt-f4
  • 2,112
  • 17
  • 49
2
votes
2 answers

How to get the next element from monix observable?

I have a stream of data that I casually log, but at a certain state of my program I need the data from the stream, not the latest observed up to that point(I can do that), but the newest one after: val dataStream : Observable[Data] = ... dataStream …
Ilya Smagin
  • 5,992
  • 11
  • 40
  • 57
2
votes
2 answers

Scala Task return mapping

I have a method readHeader which takes one argument and returns Task[List[Header]] and another method calls for multiple ids and returns List[Task[List[EquipmentHeader]]]. How to make a return of Task[List[List[Header]]] compatible with multiple id…
Sumeet Kumar Yadav
  • 11,912
  • 6
  • 43
  • 80
2
votes
2 answers

Better way to handle errors with Monix Observable

I am trying to build reactive application with monix 3.0.0-RC1. For instance a have a Seq of Int's, and the second element is wrong. I can use Oservable.raiseError(...) to handle this: Observable.fromIterable(Seq(1,2,3)) .flatMap( i => …
Oleg
  • 899
  • 1
  • 8
  • 22
2
votes
1 answer

Writing an Observable to file

I currently have the following code: val writer: PrintWriter = ??? val linesObservable: Observable[String] = ??? val future: CancelableFuture[Unit] = linesObservable.foreach(writer.write) writer.close() My goal is to get rid of all side effects…
Markus Appel
  • 3,138
  • 1
  • 17
  • 46
2
votes
2 answers

How to implement process execution as reactive `Observable[String]

I want represent external process execution as Observable[String], where String - line from process output. Here example what I do, it's worked: import monix.eval.Task import monix.execution.Scheduler.Implicits.global import…
zella
  • 4,645
  • 6
  • 35
  • 60
2
votes
1 answer

Symbol 'type cats.MonadFilter' is missing fromthe classpath

I am reading this tutorial on tagless final. Based on this I have defined my dependencies as object Dependencies { lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" lazy val cats = "org.typelevel" %% "cats-core" % "1.2.0" lazy val…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
2
votes
0 answers

Can I use Monix's backpressure mechanism to confirm delivery of the message

I have a situation when I receive messages from a 3rd party system, that guarantees delivery of the messages. In order to do that it requires the client to acknowledge each received message. An example of such system might be RibbitMQ. Now, I know…
Andrew Slabko
  • 690
  • 8
  • 15
2
votes
1 answer

Understanding observer in monix

I'm reading Monix documentation about observers ad I faced with the following example: Or you can quickly build an Observer that only logs the events that it receives. We’ll use this in other samples: import monix.reactive.Observer val out =…
St.Antario
  • 26,175
  • 41
  • 130
  • 318