abstract class Scheduler extends AnyRef
Provides operations based on the passage of cpu time.
Operations on this class generally return streams. Some operations return
effectful values instead. These operations are accessed via the .effect
method, which returns a projection consisting of operations that return
effects.
- Source
- Scheduler.scala
- Alphabetic
- By Inheritance
- Scheduler
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Scheduler()
Abstract Value Members
-
abstract
def
scheduleAtFixedRate(period: FiniteDuration)(thunk: ⇒ Unit): () ⇒ Unit
Evaluates the thunk every period.
Evaluates the thunk every period. Returns a thunk that when evaluated, cancels the execution.
- Attributes
- protected
-
abstract
def
scheduleOnce(delay: FiniteDuration)(thunk: ⇒ Unit): () ⇒ Unit
Evaluates the thunk after the delay.
Evaluates the thunk after the delay. Returns a thunk that when evaluated, cancels the execution.
- Attributes
- protected
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (Scheduler, B)
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
attempts[F[_], A](s: Stream[F, A], delays: Stream[F, FiniteDuration])(implicit F: Async[F], ec: ExecutionContext): Stream[F, Either[Throwable, A]]
Retries
s
on failure, returning a stream of attempts that can be manipulated with standard stream operations such astake
,collectFirst
andinterruptWhen
.Retries
s
on failure, returning a stream of attempts that can be manipulated with standard stream operations such astake
,collectFirst
andinterruptWhen
.Note: The resulting stream does *not* automatically halt at the first successful attempt. Also see
retry
. -
def
awakeDelay[F[_]](d: FiniteDuration)(implicit F: Async[F], ec: ExecutionContext): Stream[F, FiniteDuration]
Light weight alternative to
awakeEvery
that sleeps for durationd
before each pulled element. -
def
awakeEvery[F[_]](d: FiniteDuration)(implicit F: Effect[F], ec: ExecutionContext): Stream[F, FiniteDuration]
Discrete stream that every
d
emits elapsed duration since the start time of stream consumption.Discrete stream that every
d
emits elapsed duration since the start time of stream consumption.For example:
awakeEvery[IO](5 seconds)
will return (approximately)5s, 10s, 15s
, and will lie dormant between emitted values.This uses an implicit
Scheduler
for the timed events, and runs the consumer using theF
Effect[F]
, to allow for the stream to decide whether result shall be run on different thread pool.Note: for very small values of
d
, it is possible that multiple periods elapse and only some of those periods are visible in the stream. This occurs when the scheduler fires faster than periods are able to be published internally, possibly due to an execution context that is slow to evaluate.- d
FiniteDuration between emits of the resulting stream
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
debounce[F[_], O](d: FiniteDuration)(implicit F: Effect[F], ec: ExecutionContext): Pipe[F, O, O]
Debounce the stream with a minimum period of
d
between each element.Debounce the stream with a minimum period of
d
between each element.scala> import scala.concurrent.duration._, scala.concurrent.ExecutionContext.Implicits.global, cats.effect.IO scala> val s2 = Scheduler[IO](1).flatMap { scheduler => | val s = Stream(1, 2, 3) ++ scheduler.sleep_[IO](500.millis) ++ Stream(4, 5) ++ scheduler.sleep_[IO](10.millis) ++ Stream(6) | s.through(scheduler.debounce(100.milliseconds)) | } scala> s2.compile.toVector.unsafeRunSync res0: Vector[Int] = Vector(3, 6)
Example: -
def
delay[F[_], O](s: Stream[F, O], d: FiniteDuration)(implicit F: Async[F], ec: ExecutionContext): Stream[F, O]
Returns a stream that when run, sleeps for duration
d
and then pulls froms
.Returns a stream that when run, sleeps for duration
d
and then pulls froms
.Alias for
sleep_[F](d) ++ s
. -
def
delayedExecutionContext(delay: FiniteDuration, reporter: (Throwable) ⇒ Unit = ExecutionContext.defaultReporter): ExecutionContext
Returns an execution context that executes all tasks after a specified delay.
-
def
effect: EffectOps
Provides scheduler methods that return effectful values instead of streams.
- def ensuring(cond: (Scheduler) ⇒ Boolean, msg: ⇒ Any): Scheduler
- def ensuring(cond: (Scheduler) ⇒ Boolean): Scheduler
- def ensuring(cond: Boolean, msg: ⇒ Any): Scheduler
- def ensuring(cond: Boolean): Scheduler
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
fixedDelay[F[_]](d: FiniteDuration)(implicit F: Async[F], ec: ExecutionContext): Stream[F, Unit]
Light weight alternative to fixedRate that sleeps for duration
d
before each pulled element.Light weight alternative to fixedRate that sleeps for duration
d
before each pulled element.Behavior differs from
fixedRate
because the sleep between elements occurs after the next element is pulled whereasfixedRate
awakes everyd
regardless of when next element is pulled. This difference can roughly be thought of as the difference betweenscheduleWithFixedDelay
andscheduleAtFixedRate
injava.util.concurrent.Scheduler
.Alias for
sleep(d).repeat
. -
def
fixedRate[F[_]](d: FiniteDuration)(implicit F: Effect[F], ec: ExecutionContext): Stream[F, Unit]
Discrete stream that emits a unit every
d
.Discrete stream that emits a unit every
d
.This uses an implicit
Scheduler
for the timed events, and runs the consumer using theF
Effect[F]
, to allow for the stream to decide whether result shall be run on different thread pool.Note: for very small values of
d
, it is possible that multiple periods elapse and only some of those periods are visible in the stream. This occurs when the scheduler fires faster than periods are able to be published internally, possibly due to an execution context that is slow to evaluate.See fixedDelay for an alternative that sleeps
d
between elements.- d
FiniteDuration between emits of the resulting stream
- def formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
retry[F[_], A](fa: F[A], delay: FiniteDuration, nextDelay: (FiniteDuration) ⇒ FiniteDuration, maxRetries: Int, retriable: (Throwable) ⇒ Boolean = internal.NonFatal.apply)(implicit F: Async[F], ec: ExecutionContext): Stream[F, A]
Retries
fa
on failure, returning a singleton stream with the result offa
as soon as it succeeds.Retries
fa
on failure, returning a singleton stream with the result offa
as soon as it succeeds.- delay
Duration of delay before the first retry
- nextDelay
Applied to the previous delay to compute the next, e.g. to implement exponential backoff
- maxRetries
Number of attempts before failing with the latest error, if
fa
never succeeds- retriable
Function to determine whether a failure is retriable or not, defaults to retry every
NonFatal
. A failed stream is immediately returned when a non-retriable failure is encountered
-
def
sleep[F[_]](d: FiniteDuration)(implicit F: Async[F], ec: ExecutionContext): Stream[F, Unit]
A single-element
Stream
that waits for the durationd
before emitting unit.A single-element
Stream
that waits for the durationd
before emitting unit. This uses the implicitScheduler
to signal duration and avoid blocking on thread. After the signal, the execution continues on the supplied execution context. -
def
sleep_[F[_]](d: FiniteDuration)(implicit F: Async[F], ec: ExecutionContext): Stream[F, Nothing]
Alias for
sleep(d).drain
.Alias for
sleep(d).drain
. Often used in conjunction with++
(i.e.,sleep_(..) ++ s
) as a more performant version ofsleep(..) >> s
. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
- def →[B](y: B): (Scheduler, B)