TokenBucket

org.http4s.server.middleware.Throttle$.TokenBucket$
See theTokenBucket companion trait
object TokenBucket

Attributes

Companion
trait
Source
Throttle.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def 0nano")))(F).flatMap[TokenBucket[F]](((x$1:Unit)=>(x$1:@unchecked)match{ case_=> toFlatMapOps[F,Long](getNanoTime)(F).flatMap[TokenBucket[F]](((creationTime:Long)=>toFunctorOps[F,Ref[F,Tuple2[Double,Long]]](F.ref[Tuple2[Double,Long]](Tuple2.apply[Double,Long](capacity.toDouble,creationTime)))(F).map[TokenBucket[F]](((counter:Ref[F,Tuple2[Double,Long]])=>{ finalclass$anon()extendsTokenBucket[F]{ overridedeftakeToken:F[TokenAvailability]=toFlatMapOps[F,Tuple2[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]]](toFunctorOps[F,Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]](counter.access)(F).map[Tuple2[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]]](((values:Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]])=>{ val$2$:Tuple4[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Double,Long,Function1[Tuple2[Double,Long],F[Boolean]]]=(values:Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]@unchecked)match{ case$1$@Tuple2(Tuple2(previousTokens,previousTime),setter)=> Tuple4.apply[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Double,Long,Function1[Tuple2[Double,Long],F[Boolean]]]($1$,previousTokens,previousTime,setter) } val`$1$₂`:Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]=$2$._1 val`previousTokens₂`:Double=$2$._2 val`previousTime₂`:Long=$2$._3 val`setter₂`:Function1[Tuple2[Double,Long],F[Boolean]]=$2$._4 Tuple2.apply[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]](values,`$1$₂`) })))(F).flatMap[TokenAvailability](((`x$1₂`:Tuple2[Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]],Tuple2[Tuple2[Double,Long],Function1[Tuple2[Double,Long],F[Boolean]]]])=>(`x$1₂`:@unchecked)match{ caseTuple2(values,Tuple2(Tuple2(previousTokens,previousTime),setter))=> toFlatMapOps[F,Long](getNanoTime)(F).flatMap[TokenAvailability](((currentTime:Long)=>toFunctorOps[F,TokenAvailability]({ valtimeDifference:Long=currentTime.-(`previousTime₃`) valtokensToAdd:Double=timeDifference.toDouble./(refillEveryNanos.toDouble) valnewTokenTotal:Double=Math.min(`previousTokens₃`.+(tokensToAdd),capacity.toDouble) if(newTokenTotal.>=(1))catsSyntaxIfM[F](`setter₃`.apply(Tuple2.apply[Double,Long](newTokenTotal.-(1),currentTime)))(F).ifM[TokenAvailability](F.pure[TokenAvailability]((TokenAvailable:TokenAvailability)),$anon.this.takeToken)(F)else{ defunavailable:TokenAvailability={ valtimeToNextToken:Long=refillEveryNanos.-(timeDifference) TokenUnavailable.apply(catsSyntaxOptionId[FiniteDuration](DurationLong(timeToNextToken).nanos).some) } catsSyntaxIfM[F](`setter₃`.apply(Tuple2.apply[Double,Long](newTokenTotal,currentTime)))(F).ifM[TokenAvailability](F.pure[TokenAvailability](unavailable),$anon.this.takeToken)(F) } })(F).map[TokenAvailability](((token:TokenAvailability)=>token)))) })) } (new$anon():TokenBucket[F]) })))) })) }" t="n"class="documentableName ">local[F[_]](capacity: Int, refillEvery: FiniteDuration)(implicit F: Temporal[F]): F[TokenBucket[F]]

Creates an in-memory TokenBucket.

Creates an in-memory TokenBucket.

Value parameters

capacity

the number of tokens the bucket can hold and starts with.

refillEvery

the frequency with which to add another token if there is capacity spare.

Attributes

Returns

A task to create the TokenBucket.

Source
Throttle.scala