Questions tagged [monix]

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

94 questions
1
vote
2 answers

Monix task handle failure for list of futures

How can I handle the failure during the asynchronous execution of the task? I.e. at least print the stack trace and shut down. The code below seems to wait forever for input > 5 val things = Range(1, 40) implicit val scheduler =…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
1
vote
0 answers

Circuit breaker monix with Http request

I´m struggling to make the Circuit breaker of Monix works async with some request that I´m receiving in my service, and that are failing, so it should activate the Circuit breaker, and even when is open it must render the request. Here my code …
paul
  • 12,873
  • 23
  • 91
  • 153
1
vote
1 answer

Atomic compareAndSet parameters are evaluated even if it's not used

I have the following code that set the Atomic variable (both java.util.concurrent.atomic and monix.execution.atomic behaves the same: class Foo { val s = AtomicAny(null: String) def foo() = { println("called") /* Side Effects */ …
SwiftMango
  • 15,092
  • 13
  • 71
  • 136
1
vote
0 answers

I get inconsistent results from Monix firstOptionL - race condition?

I get an intermittent missing value from repeated calls to the same (MongoDB) database call which I've converted into an Observable. I've removed all database code to get a minimal test case which only has the Monix bits and I'm still missing values…
ElaineC
  • 11
  • 1
1
vote
2 answers

Converting from Task[Either[A, Task[B]]] to Task[Either[A, B]]

I am using monix for side effects and ended with this type Task[Either[A, Task[B]]], Is there a way to get Task[Either[A, B]]? So far all I could do is convert Task[Either[A, Task[B]]] to Task[Any], basically removing Either using pattern matching…
Satya
  • 13
  • 1
  • 2
1
vote
1 answer

How to handle errors and keep an Observable alive in .mapParallelUnordered

I am using Monix 3 and have a kind of this code: Observable.fromIterable(Seq(1, 2, 3, 4, 5, 6, 7, 8, 9)) .flatMap(i => if (i % 2 == 0) { // Bad i Observable.empty } else Observable.pure(i) ) .foreachL(i =>…
Oleg
  • 899
  • 1
  • 8
  • 22
1
vote
1 answer

monix: Task.executeWithFork prevents execution?

I can't figure out why adding executeWithFork prevents task from running in the following example: import java.util.concurrent.TimeUnit import monix.execution.schedulers.SchedulerService import monix.reactive.subjects.ConcurrentSubject object…
eprst
  • 733
  • 6
  • 14
1
vote
1 answer

Why Monix Observable produces one element more than needed

I'm playing with Monix streams and got the example where I build Observable from Iterator. It seems to me like when run it produces 1 more element than I'd expect. The following code shows that: val count = AtomicLong(0) def produceValue(): Long…
Michal Ostruszka
  • 2,089
  • 2
  • 20
  • 23
1
vote
1 answer

Replay cached items in reverse order on subscribe

I have a ConnectableObservable which upon subscribe, will replay the last x items in their original order (oldest to newest) and any subsequent events after. I am using this Observable as the backing store for an event blotter, however upon…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
1
vote
1 answer

Scala Cats: tail recursive tailRecM method for Monad Instance of Task[Validated[String,?]

In cats, when a Monad is created using the Monad trait, ideally a tail-recursive implementation for method tailRecM should be provided to ensure stack safety. I am using the tagless final approach and wish to have an effect of Task[Validated[String,…
1
vote
1 answer

Type alias and implicit value resolution

I assume this is an easy one but I’m running into problem where the FlatMap or Functor of a Monix Task cannot be found. I use a "type alias" to simplify a long type signiture but then in the for-comprehession I receive a "could not find implicit…
Adam Wayland
  • 354
  • 1
  • 2
  • 9
1
vote
1 answer

In Scala Monix Scheduler how to propagate exceptions to main program?

I have a Monix Scheduler that scheduling error-prone task: import scala.concurrent.duration._ import monix.eval.Task import monix.execution.Scheduler import java.time._ scheduler.scheduleWithFixedDelay(0.seconds, 1.seconds) { …
WeiChing 林煒清
  • 4,452
  • 3
  • 30
  • 65
1
vote
0 answers

How can the caller Task avoid having it's scheduler changed by a sub task that it flatMap's over

I'm looking for a way in which a Task (i.e. outer scope) could execute a "subTask" using flatMap or something equivalent and make sure that any subsequent chained calls in the outer scope use the original scheduler. Libraries and scala used: scala…
1
vote
2 answers

Scala Monix , how to kill running or scheduled Task

Im using Monix for asynchronous task workflow. How do we kill a running Task ? Task{ println("sleep") Thread.sleep(200) println("effect") } .doOnCancel(Task(println("canceled"))) .timeout(100.milli) // timeout will do…
WeiChing 林煒清
  • 4,452
  • 3
  • 30
  • 65
1
vote
1 answer

Usage of Monix Debounce Observable

I'm trying out some of the operations that I could do on the Observable from Monix. I came across this debounce operator and could not understand its behavior: Observable.interval(5.seconds).debounce(2.seconds) This one above just emits a Long…
joesan
  • 13,963
  • 27
  • 95
  • 232