Skip to content

Instantly share code, notes, and snippets.

View leandrob13's full-sized avatar

Leandro Bolivar leandrob13

View GitHub Profile
trait Operation
trait Revert
trait Transaction[R <: Revert, O <: Operation]
@leandrob13
leandrob13 / KafkaProtobufEncoder.scala
Last active January 20, 2017 15:27
How to resolve implicitly the companion of a protobuf class. The issue on ScalaPB regarding this proposal is: https://github.com/scalapb/ScalaPB/issues/229
trait Event
object KafkaEncoder {
type KafkaProtobufEvent[T <: Event] = GeneratedMessage with Message[T] with Updatable[T] with Event
type KafkaProtobufEncoder[E <: KafkaProtobufEvent[E]] = GeneratedMessageCompanion[E]
def apply[T <: KafkaProtobufEvent[T]](implicit enc: KafkaEncoder[T]) = enc
def serialize[T <: KafkaProtobufEvent[T]](data: T)(implicit companion: KafkaProtobufEncoder[T]): Array[Byte] =
package imperative
import fp.{Book, Genre}
import scala.collection.mutable.ListBuffer
import scala.util.matching.Regex
trait BookValidation {

Keybase proof

I hereby claim:

  • I am leandrob13 on github.
  • I am leandrob13 (https://keybase.io/leandrob13) on keybase.
  • I have a public key ASAcSFjE2RJe6nAChUDEdAQGQVC1ART7TD7aAi5zCqeOJwo

To claim this, I am signing this object:

I have been doing some follow up to TaskLocal and I have put together some tests to illustrate some of the findings.

TaskLocal.bind looks like this:

  def bind[R](value: A)(task: Task[R]): Task[R] =
    Task.suspend {
      val saved = ref.value
      ref.update(value)
     // the cleanup occurs in the thread where the task executes.
import monix.eval.{Task, TaskLocal}
import monix.execution.{CancelableFuture, Scheduler}
trait TracingContext {
def asCurrent[T](t: Task[T]): Task[T]
def execute[T](t: Task[T])(implicit sch: Scheduler, opt: Task.Options): CancelableFuture[T]
}
import monix.eval.Task
import monix.execution.{CancelableFuture, Scheduler}
case class TracingIds(ids: Map[String, String]) extends TracingContext {
import TracingIds._
def asCurrent[T](t: Task[T]): Task[T] =
TracingIds.bind(this)(t)
def execute[T](t: Task[T])(implicit sch: Scheduler, opt: Task.Options): CancelableFuture[T] = {
import monix.eval.Task
import monix.execution.Scheduler
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{Inside, MustMatchers, WordSpec}
import scala.concurrent.Future
class TracingIdsTest extends WordSpec with MustMatchers with ScalaFutures with Inside {
import minitest.SimpleTestSuite
import monix.execution.Scheduler
object TaskLocalSuite extends SimpleTestSuite {
implicit val ec: Scheduler = monix.execution.Scheduler.Implicits.global
implicit val opts = Task.defaultOptions.enableLocalContextPropagation
testAsync("Local.apply") {
val test =
for {
import minitest.SimpleTestSuite
import monix.execution.Scheduler
object TaskLocalSuite extends SimpleTestSuite {
implicit val ec: Scheduler = monix.execution.Scheduler.Implicits.global
implicit val opts = Task.defaultOptions.enableLocalContextPropagation
testAsync("TaskLocal.bind clears local with no async boundary") {
val local = TaskLocal(0)