This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Cached { | |
def create[F[_]: Concurrent, A](fa: F[A], ttl: FiniteDuration)(implicit t: Timer[F]): F[Cached[F, A]] = { | |
sealed trait State | |
case class Value(v: A, ts: Long) extends State | |
case class Updating(d: Deferred[F, Either[Throwable, A]]) extends State | |
case object NoValue extends State | |
def currentTimestamp = t.clock.monotonic(ttl.unit) | |
Ref.of[F, State](NoValue).map { state => | |
new Cached[F, A] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs2.Stream | |
import fs2.concurrent.Queue | |
import cats.implicits._ | |
import cats.effect.implicits._ | |
import cats.effect.{Concurrent, Resource} | |
import scala.language.higherKinds | |
abstract class JobSubmission[F[_], A]{ | |
def submit(a: A): F[Unit] | |
} |