abstract class Scheduler extends AnyRef
Provides the ability to schedule evaluation of thunks in the future.
- 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
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
- @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.runLog.unsafeRunSync res0: Vector[Int] = Vector(3, 6)
Example: -
def
delayedExecutionContext(delay: FiniteDuration, reporter: (Throwable) ⇒ Unit = ExecutionContext.defaultReporter): ExecutionContext
Returns an execution context that executes all tasks after a specified delay.
-
def
duration[F[_]](implicit F: Sync[F]): Stream[F, FiniteDuration]
A continuous stream of the elapsed time, computed using
System.nanoTime
.A continuous stream of the elapsed time, computed using
System.nanoTime
. Note that the actual granularity of these elapsed times depends on the OS, for instance the OS may only update the current time every ten milliseconds or so. - 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
every[F[_]](d: FiniteDuration): Stream[F, Boolean]
A continuous stream which is true after
d, 2d, 3d...
elapsed duration, and false otherwise.A continuous stream which is true after
d, 2d, 3d...
elapsed duration, and false otherwise. If you'd like a 'discrete' stream that will actually block untild
has elapsed, useawakeEvery
instead. -
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
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
- @throws( ... )
- def →[B](y: B): (Scheduler, B)