by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Fabio Labella
@SystemFw
at the end of the day, it's always up to the user to give a hint about blocking stuff
that's what blocking on global does
and what we achieve with ContextShift
Alexandru Nedelcu
@alexandru
Btw, I think Scala's global, which is a ForkJoinPool, works better as a default for CPU-bound stuff. Does some nifty work stealing stuff under the hood and the blocking integration is pretty cool too.
Talking about usage of Executors.newFixedThreadPool in Scalaz's RTS.
Mateusz Górski
@goral09
That would be my default choice as well.
Piotr Gawryś
@Avasil
How work stealing works for typicalIO/Task code? I don't see how it can be split. I have been wondering about it for a while and didn't find satisfactory answer yet
Fabio Labella
@SystemFw
yeah, I also prefer global, but that fixedThreadPool code doesn't particularly surprise me
the old Strategy in the scalaz world had that as a default
Alex Henning Johannessen
@ahjohannessen
@alexandru When do you expect to publish a Monix v3 that works with cats-effect 1.0.0?
Wogan
@wogan
Alex you can watch #710 for progress
Yann Simon
@yanns
Hello, newbie question: how do we transform an Observable[List[A]] into an Observable[A]?
Yohann B
@ybr
@yanns You can do myobs.flatMap(myList => Observable(myList.toSeq: _*)) or something like that
Yann Simon
@yanns
Thx, This is working (.flatMap(list ⇒ Observable.fromIterator(list.iterator))).
I was looking for a method that can do it directly like the mapConcat in akka streams.
Alexandru Nedelcu
@alexandru
Sorry guys, I cannot release a new versions with an API that I don't want to support in the final release. Cats-Effect 1.0.0 triggered some major changes in Task and the monix-eval sub-project, I have to finish that first. Working as hard as possible, given work and other obligations.
Alex Henning Johannessen
@ahjohannessen
@alexandru thanks for heads up
Jason Riddle
@jason-riddle
Has anyone successfully used Monix with OpenTracing? More specifically is there an example on how to trace a Monix task?
Alexandru Nedelcu
@alexandru
@jason-riddle what's OpenTracing?
toxicafunk
@toxicafunk
is that what sleuth and dapper and zipkin does?
if so, I don't think there's nothing relevant/specific to monix
Alejandro Gómez
@purrgrammer
hi folks, I'm finding a problem when trying to get a ContextShift[Task] from a Scheduler instance. If i understood correctly, you can do Scheduler#timer and Scheduler#contextShift provided that the right implicits are imported. However, when trying to create a ContextShift from a scheduler instance (https://github.com/47deg/fetch/blob/4328bc61627eaf580624ec825cd63bbe17526659/examples/src/test/scala/MonixExample.scala#L44-L46) I get the following error: value contextShift is not a member of monix.execution.Scheduler
not sure what I'm doing wrong, any input would be appreciated
Piotr Gawryś
@Avasil
It's not in 3.0.0-RC1 but you can try 3.0.0-RC2-d0feeba with cats-effect 1.0.0-RC3
Alejandro Gómez
@purrgrammer
@Avasil oh, my bad then, thanks for pointing me in the right direction
Alexandru Nedelcu
@alexandru
Shit, I really need to publish something fast.
Mateusz Górski
@goral09
That's the price of a success @alexandru :)
Igor Ramazanov
@igor-ramazanov

Hey guys! I'm working on a personal pet-project learning final-tagless and functional programming. Usually I was using Monix through its direct API.
Currently, I'm trying to abstract over the Task, so choosing of the effect monad will be deferred until the end of the world.
I've faced with a problem of being unable to express some functionality using cats-effect:

Task(...).onErrorRestartLoop(MaxRetries) { (ex, retries, retry) =>
        if (retries > 0) {
          retry(retries - 1).delayExecution(1.second)
        } else {
          onError(ex)
          Task.raiseError(ex)
        }
      }

This is a simple retries mechanism with a retries number threshold and delayed execution of retries.

Gabriel Volpe
@gvolpe
@themirrortruth I'm not super familiar with monix Task but more with cats-effect. If you can tell me what is the type of retry I might be able to help you
Gabriel Volpe
@gvolpe
I believe it does something like this:
import cats.MonadError
import cats.effect.Timer
import cats.syntax.all._

import scala.concurrent.duration._

def retry[F[_], A](fa: F[A])(retries: Int)(implicit F: MonadError[F, Throwable], T: Timer[F]): F[A] =
  fa.handleErrorWith {
    case _ if retries > 0 =>
      T.sleep(1.second) >> retry(fa)(retries - 1)
    case e =>
      F.raiseError(e)
  }

Example of use:

// not sure if Task.raiseError exists, maybe Task.eval(throw exception) will do
val task = Task.eval(println("foo")) *> Task.raiseError(new Exception("boom"))
retry(task)(5)

Output:

foo
foo
foo
foo
foo
foo
java.lang.Exception: boom
Alexandru Nedelcu
@alexandru
@gvolpe @themirrortruth in addition to modelling your own loop, Monix also has onErrorRestartLoop, so you can do ...
task.onErrorRestartLoop(retries) { (e, retries, retry) =>
  if (retries > 0)
    Task.sleep(1.second).flatMap(_ => retry(retries - 1))
  else
    Task.raiseError(e)
}

New PR: monix/monix#726

Oleg Pyzhcov
@oleg-py
So it's catnap now :D
Alexandru Nedelcu
@alexandru
catnip was taken :)
Oleg Pyzhcov
@oleg-py
It's so cold and rainy outside, I could use a catnap myself
Alexandru Nedelcu
@alexandru
Yes, laziness wins 😛
Oleg Pyzhcov
@oleg-py
But not by default :smirk:
Alexandru Nedelcu
@alexandru
@themirrortruth for your question, @gvolpe's answer is correct ... onErrorRestartLoop is basically just a loop built with onErrorHandleWith, named handleErrorWith in Cats (which is flatMap for errors)
Gabriel Volpe
@gvolpe
:+1: :smiley:
Igor Ramazanov
@igor-ramazanov
@alexandru @gvolpe Thank you!
SemanticBeeng
@SemanticBeeng
Trying to use cats.data.Nested with Task based apis and getting stuck
      type Dataset = (DataSpecification, DataSetRef)

      val clients = Nested[Task, Either[DataLakeRepositoryError, ?], Seq[Client]](dlRegistry.listClients())

      def clientDatasets(client: String) =
        Nested[Task, Either[DataLakeRepositoryError, ?], Seq[Dataset]](dlRegistry.listDatasets(client))

      val r: Task[_] = (clients map { cls: Seq[Client] ⇒
        cls map { client ⇒
            (clientDatasets( client.id) map { dsds: Seq[Dataset] ⇒
              dsds map { ds ⇒
                ds._2.shortName.pp("\n\n"); ds
              }
            }).value
          }

        }).value

     s"r is ${await(r)}".pp
Gives r is Right(List(Task.Map$995060245, Task.Map$958851644, Task.Map$119297310, Task.Map$713902690, Task.Map$1792185060, Task.Map$1688986248))
SemanticBeeng
@SemanticBeeng
Instead I'd like a single Task to runAsync for result.
Tried Task.sequence and other things but the result is always something else than desired.
For context about cats.data.Nested see https://typelevel.org/cats/datatypes/nested.html
You can glean from code above but apis are