Timed
An abstraction for writing
while reading from a
Pull
computations that can timeoutwhile reading from a
Stream
.{{{
yourStream.pull.timed(tp => ...).stream
}}}
yourStream.pull.timed(tp => ...).stream
}}}
The argument to
function, which describes the pulling logic and is often recursive,
with shape:
timed
is a Pull.Timed[F, O] => Pull[F, O2, R]
function, which describes the pulling logic and is often recursive,
with shape:
{{{
def go(timedPull: Pull.Timed[F, A] ): Pull[F, B, Unit] =
timedPull.uncons.flatMap {
case Some((Right(chunk), next)) => doSomething >> go(next)
case Some((Left(_), next)) => doSomethingElse >> go(next)
case None => Pull.done
}
}}}
def go(timedPull: Pull.Timed[F, A] ): Pull[F, B, Unit] =
timedPull.uncons.flatMap {
case Some((Right(chunk), next)) => doSomething >> go(next)
case Some((Left(_), next)) => doSomethingElse >> go(next)
case None => Pull.done
}
}}}
Where
such as
doSomething
and doSomethingElse
are Pull
computationssuch as
Pull.output
, in addition to Pull.Timed.timeout
.See below for detailed descriptions of
look at the Stream.ToPull.timed scaladoc for an example of usage.
timeout
and uncons
, andlook at the Stream.ToPull.timed scaladoc for an example of usage.
class Object
trait Matchable
class Any
Type members
Types
Value members
Methods
Waits for either a chunk of elements to be available in the
source stream, or a timeout to trigger. Whichever happens
first is provided as the resource of the returned pull,
alongside a new timed pull that can be used for awaiting
again. A
reaching the end of the stream.
source stream, or a timeout to trigger. Whichever happens
first is provided as the resource of the returned pull,
alongside a new timed pull that can be used for awaiting
again. A
None
is returned as the resource of the pull uponreaching the end of the stream.
Receiving a timeout is not a fatal event: the evaluation of the
current chunk is not interrupted, and the next timed pull is
still returned for further iteration. The lifetime of timeouts
is handled by explicit calls to the
does not start, restart or cancel any timeouts.
current chunk is not interrupted, and the next timed pull is
still returned for further iteration. The lifetime of timeouts
is handled by explicit calls to the
timeout
method: uncons
does not start, restart or cancel any timeouts.
Note that the type of timeouts is existential in
(hidden, basically) so you cannot do anything on it except for
pattern matching, which is best done as a
Pull.Timed
(hidden, basically) so you cannot do anything on it except for
pattern matching, which is best done as a
Left(_)
case.Asynchronously starts a timeout that will be received by
uncons
after t
, and immediately returns.Timeouts are resettable: if
previous timeout is pending, it will cancel it before starting
the new one, so that there is at most one timeout in flight at
any given time. The implementation guards against stale
timeouts: after resetting a timeout, a subsequent
guaranteed to never receive an old one.
timeout
executes whilst aprevious timeout is pending, it will cancel it before starting
the new one, so that there is at most one timeout in flight at
any given time. The implementation guards against stale
timeouts: after resetting a timeout, a subsequent
uncons
isguaranteed to never receive an old one.
Timeouts can be reset to any
previous timeout, but a duration of 0 is treated specially, in
that it will cancel a pending timeout but not start a new one.
t
, longer or shorter than theprevious timeout, but a duration of 0 is treated specially, in
that it will cancel a pending timeout but not start a new one.
Note: the very first execution of
running until the first call to
proceed independently after that.
timeout
does not startrunning until the first call to
uncons
, but subsequent callsproceed independently after that.