Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 05 2019 14:43
    @typelevel-bot banned @jdegoes
  • Jan 31 2019 21:17
    codecov-io commented #484
  • Jan 31 2019 21:08
    scala-steward opened #484
  • Jan 31 2019 18:19
    andywhite37 commented #189
  • Jan 31 2019 02:41
    kamilongus starred typelevel/cats-effect
  • Jan 30 2019 00:01
    codecov-io commented #483
  • Jan 29 2019 23:51
    deniszjukow opened #483
  • Jan 29 2019 23:37
  • Jan 29 2019 23:22
  • Jan 29 2019 20:26
    Rui-L starred typelevel/cats-effect
  • Jan 29 2019 18:01
    jdegoes commented #480
  • Jan 29 2019 17:04
    thomaav starred typelevel/cats-effect
  • Jan 28 2019 17:43
    asachdeva starred typelevel/cats-effect
  • Jan 28 2019 07:12
    alexandru commented #480
  • Jan 28 2019 05:45
    codecov-io commented #482
  • Jan 28 2019 05:35
    daron666 opened #482
  • Jan 27 2019 13:56
    codecov-io commented #481
  • Jan 27 2019 13:46
    lrodero opened #481
  • Jan 27 2019 05:47
    codecov-io commented #460
  • Jan 27 2019 05:37
    codecov-io commented #460
Mark de Jong
@Fristi
Wonder if I could decorate ContextShiftto propagate the right MDC context as seen in http://code.hootsuite.com/logging-contextual-info-in-an-asynchronous-scala-application/
Alexandru Nedelcu
@alexandru

@Fristi in Monix you can use a TracingScheduler, out of which you can build the proper ContextShift, for IO too, however it gets tricky — and the reason for why the logic for Monix's TaskLocal resides in the Task run-loop itself.

For instance all it takes to screw your locals is something like this and your special ContextSwitch won't help 😉

IO.async { cb =>
  new Thread(() -> cb(Right(()))).start()
}
Monix's Task protects against this of course, by restoring the original locals after such async tasks are done executing.
For simple use-cases, you might get away with it though.
Note that you can easily build a ContextSwitch out of a Monix TrackingScheduler and you can use the low-level Local in monix-execution, so you could do something with IO, but you have to keep in mind the above gotcha.
Mark de Jong
@Fristi
Thanks, I will have a stab at it
Fabio Labella
@SystemFw
is it worth doing all this to avoid saying myCall(id)(otherArgs)? genuine question
Georgi Krastev
@joroKr21
The problem is propagating otherArgs all the way through to your log statements
But I like using ApplicativeAsk for something like that (from cats-mtl)
Fabio Labella
@SystemFw
(you can use a custom Loggertypeclass as well)
Georgi Krastev
@joroKr21
yeah that's also an option
Alexandru Nedelcu
@alexandru
TBH logging is one of the things I hate about Haskell 🙂
Georgi Krastev
@joroKr21
if logging is all you're gonna use this value for
Fabio Labella
@SystemFw
You can remove "about Haskell" and it still works fine ;)
Alexandru Nedelcu
@alexandru
True
Georgi Krastev
@joroKr21
Unrelated question, I've been wondering something for two days - is there anything wrong with this?
def defaultContextShift[F[_]: Async](implicit ec: ExecutionContext): ContextShift[F] = new ContextShift[F] {
    def shift: F[Unit] = Async.shift(ec)
    def evalOn[A](ec: ExecutionContext)(fa: F[A]): F[A] =
      Async[F].bracket(Async.shift(ec))(_ => fa)(_ => shift)
  }
Fabio Labella
@SystemFw
you might lose some optimisations (I need to check) but no that's basically ok. What's the point though? you don't save much in ergonomics
Jakub Kozłowski
@kubukoz
I wouldn't make the ec implicit
Alexandru Nedelcu
@alexandru
The point of ContextShift[F] is that it needs to be provided by the effect type. This is why there is no such default defined in Cats-Effect. Because that evalOn that you've described only works reliably for cats.effect.IO.
So no, I wouldn't use defaultContextShift anywhere. If you need ContextShift[F], then get it as a function parameter.
Fabio Labella
@SystemFw
ah, that's right, autoshifting probably wreaks havoc with that
Georgi Krastev
@joroKr21
It's for introp with scalaz task
So I have to implement ContextShift myself ofc and there is no autoshiftinh
Argh on phone sorry about the typos
Fabio Labella
@SystemFw
does Concurrent[scalaz.Task] work?
(curiosity)
Georgi Krastev
@joroKr21
No, you have no finalizers
You can't observe cancellation
Fabio Labella
@SystemFw
what is bracket then?
Georgi Krastev
@joroKr21
You have upto Effect so you just can't do cancellation
Fabio Labella
@SystemFw
I mean, you can (you can run it interruptibly) and it will probably break, but I guess one has to live with those limitations
I would do that if you like
Alexandru Nedelcu
@alexandru
For the Scalaz Task that implementation of ContextShift should work fine
@Odomontois RefM would probably be cool, but I see that it needs a Queue too and that may be out of scope, queues are complicated.
Also if you do anything, it will need proper attribution.
Odomontois
@Odomontois
@alexandru so should I move this question to fs2? It has queues
Jakub Kozłowski
@kubukoz
you could
Alexandru Nedelcu
@alexandru
Monix has queues too. Maybe we need a Queue interface in Cats-Effect that we can extend or something.
So the answer is that I don't know at this point. Also see what the others think.
Fabio Labella
@SystemFw
we had a massive discussion about RefM already, you might want to check that out
both in this channel, and in the MVar.modifyF issue
in the meantime: if you have a simple case, you can use Semaphore.withPermit + Ref. The interface is perhaps not as nice as having a modifyF but it's serviceable. If you have a complex case, you shouldn't use RefM nor Semaphore nor essentially a locking structure, if you can (my personal suggestion is Ref + Deferred, but there are others)
Odomontois
@Odomontois
I thought about general purpose simple data-structure like clojure agent.
Yeah actually Semaphore.withPermit suits me well
Georgi Krastev
@joroKr21
I mean, you can (you can run it interruptibly) and it will probably break, but I guess one has to live with those limitations
Just don't do that :D
Fabio Labella
@SystemFw
yeah :)
Mark de Jong
@Fristi

Seems for logging (MDC) and http4s a combination of https://olegpy.com/better-logging-monix-1/ and this

  def http4sMiddleware[F[_]: Sync]: HttpMiddleware[F] = outer => {
    Kleisli { req =>
      val setCid: F[Unit] = Sync[F].delay {
        val cid = req.headers.get(CaseInsensitiveString("X-Correlation-Id")) match {
          case None            => UUID.randomUUID().toString
          case Some(cidHeader) => cidHeader.value
        }

        MDC.put("cid", cid)
      }

      OptionT.liftF(setCid) *> outer(req)
    }
  }

Is working fine :-)

Along with local context propagation