Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Phong Nguyen
@phongngtuan
@sirmax got it, many thanks :)
Mateusz Górski
@goral09
is there an option that would shift at every flatMap/map call ?
Oleg Pyzhcov
@oleg-py
@goral09 task.executeWithModel(ExecutionModel.AlwaysAsyncExecution)
Mateusz Górski
@goral09
Thanks @oleg-py , this works great :)
it's much better thank shift-ing after every call xD
Ilya Murzinov
@ilya-murzinov

hi guys, I started working on #690 and can't figure out why my test is not starting :(
here is the code
monix/monix@b827aaf

reactiveJVM/testOnly *TypeClassLawsForObservableSuite <- works as expected
reactiveJVM/testOnly *TypeClassLawsForSubjectSuite <- doesn't do anything like there no test

Piotr Gawryś
@Avasil
I dont have access to my computer right now so I dont have ideas other than reloading sbt :D what if you put this test with the rest?
Ilya Murzinov
@ilya-murzinov
lol, if I just put checkAllAsync("Profunctor[Subject]") { implicit ec => ??? } in TypeClassLawsForObservableSuite it stops running at all
Oleg Pyzhcov
@oleg-py
maybe that's because ??? throws
Ilya Murzinov
@ilya-murzinov
not only my test, it doesn't run whole suite anymore
??? is just a placeholder
Martijn Hoekstra
@martijnhoekstra
??? is just def ???: Nothing = throw new NotImplementedException("an implementation is missing") -- bringing that into an implicit scope does sound like it could seriously mess something up
mark lister
@marklister
Is it possible to restart an observable?
Mateusz Górski
@goral09
@marklister what do you want to achieve?
mark lister
@marklister
I have one observable performing a expensive operation every twenty minutes and another filling in once a second. I'd like to restart the second one from zero whenever the second one successfully emits
Maybe if I use onErrorRestartUnlimited and induce an error?
Oleg Pyzhcov
@oleg-py

@marklister I'd do

val ticker = expensive.switchMap(_ => mk1SecondObservable)

(if expensive is a hot observable)

mark lister
@marklister
@oleg-py Ok thanks! Will give that a go!
Ilya Murzinov
@ilya-murzinov
@martijnhoekstra yep, that was the case, I removed all ??? from every place and now everything works
mark lister
@marklister
@oleg-py switchmap worked perfectly thank you!
Itamar Ravid
@iravid
Is there a published hash version that works with cats-effect 1.0.0?
Alexandru Nedelcu
@alexandru
None that I can recommend. But today I'm wrapping up the auto-cancelable PR and will make a hash version available tonight.
Will ping you when available.
Oleg Pyzhcov
@oleg-py
Guess it's finally gonna be time to include Monix in my pet project :)
Itamar Ravid
@iravid
Thanks @alexandru!
Felix Dietze
@fdietze
ScalaJS: I just found that window.setTimeout(..., 0) has a small delay. Would it be possible to use setImmediate using a polyfill instead? I'd like to know if it makes a difference for my application. Is it correct that I have to reimplement AsyncScheduler using setImmediate?
Jules Ivanic
@guizmaii

Hi everyone,

It’s possible to cancel a pure computation task ?
Example of what I’m trying to do:

val heuristic: Task[Option[A]] = ???
val bruteForce: Task[Option[A]] = ???

      Task
        .racePair(heuristic, bruteForce)
        .flatMap {
          case Left((Some(a), slower))  => slower.cancel.map(_ => Some(a))
          case Left((None, slower))     => slower.join
          case Right((slower, Some(b))) => slower.cancel.map(_ => Some(b))
          case Right((slower, None))    => slower.join
        }
We observe strange results in our benchmarks.
Oleg Pyzhcov
@oleg-py
@guizmaii yes, it is possible, but Tasks are only cancelable on async boundaries (e.g. when doing Task.shift) and if executed with autoCancelable (IIRC that's the name), or when doing Task.cancelBoundary
I.e. if you do Task { inline hot loop }, it's effectively not cancelable at all
Jules Ivanic
@guizmaii

I’m not sure to understand everything you said.

racePair doesn’t shift automatically ?

Oleg Pyzhcov
@oleg-py
You cannot cancel a Task in the middle of loop, if the loop does not include shifts inside
or if it's not build using a cancelable builder
Well, I'm not entirely correct. You can cancel it so it never completes, but you cannot prevent it from wasting CPU resources, which is what I'm assuming you're looking to do
Jules Ivanic
@guizmaii
🤔

This is not cancellable:

Task.delay { … }

while, this, is:

Task.delay { … }.shift

??

Oleg Pyzhcov
@oleg-py
Nope. In both cases, the ... part will either always execute in its entirety, or never execute at all.

but here

for {
a <- Task { ... A ... }
_ <- Task.shift
 b <- Task { ... B ...}
} yield a + b

Either nothing executes, or A is executed, or A and B are both executed

But you won't get a case where A is half-executed and then stopped in the middle
Jules Ivanic
@guizmaii

With this:

      heuristic.flatMap {
        case Some(a) => Task.now(Some(a))
        case _ => bruteForce
      }

My benchmark gives me ~4000 ops/s

While with this

      bruteForce.flatMap {
        case Some(a) => Task.now(Some(a))
        case _       => heuristic
      }

The same benchmark gives me ~5 ops/s

So I don’t understand why with this code:

      Task
        .racePair(heuristic, bruteForce)
        .flatMap {
          case Left((Some(a), _))    => Task.now(Some(a)) // I don’t cancel anymore here 
          case Left((None, slower))  => slower.join
          case Right((_, Some(b)))   => Task.now(Some(b)) // I don’t cancel anymore here 
          case Right((slower, None)) => slower.join
        }

The same benchmark gives me ~40 ops/s

With this last impl, I was expecting to get the 4000 ops/s.

I wast resources in the last impl but I should get the 4000 ops/s, no ?
Oleg Pyzhcov
@oleg-py
If you're always executing brute force even if you're not interested in its result, you waste CPU cycles so you get less ops/s
Your code might be computing brute force impls for the previous 10 runs where heuristic was enough, but you didn't interrupt the execution of brute-force
so it will run until completion anyway
It has to do with how tasks are constructed even more than it has to do with how they are executed.
Jules Ivanic
@guizmaii
interesting. Any way to cancel bruteForce ? or I’m fucked and will have to suffer this perf lost ?
Piotr Gawryś
@Avasil
The only way is to shift inside bruteFroce from time to time. Ideally cancelBoundary after Alex finishes new changes
Jules Ivanic
@guizmaii
bruteFroce is just pure computation.
      val bruteForce =
        Task
          .async { (scheduler, cb) =>

            scheduler.execute(new Runnable { override def run(): Unit = {
              try {
                cb(...)
              } catch {
                _ => cb(null)
              }
            } })

            Cancelable.empty
          }
what about something like that ?