in src/main/scala/com/twitter/stitch/Stitch.scala [1644:1703]
def sleep(d: util.Duration)(implicit timer: Timer): Stitch[Unit] =
if (d <= util.Duration.Zero)
Stitch.Done
else
call((), SleepGroup(d, timer))
/**
* let-scope a [[Local]] around the contained [[Stitch]] `s`
*
* This is equivalent to `local.let(local)(a)` but correctly applies the `local` to the `s`'s execution.
*
* @note [[let]] applies the [[Local]] __only non-batched operations__,
* [[call]] and [[Group]]s do not have access to [[Local]]s set with [[let]].
* To access a [[Local]] value within a [[call]], or [[Group]], access the value
* before making your [[call]] and add it to your input.
* For instance,`s.map(v => (v, local())).call(...)`
*
* @param local the [[Local]] that should be let-scoped around `a`
* @param value the value of the `local` within the execution of `s`
* @param s the underlying [[Stitch]] which will have the `local` set during it's evaluation
* @tparam L the type of the [[Local]] and it's value
*/
def let[T, L](local: Local[L])(value: L)(s: => Stitch[T]): Stitch[T] =
let(LocalLetter(local))(value)(s)
/**
* clear a [[Local]] around the contained [[Stitch]] `s`
*
* This is equivalent to `LetClearer.letClear(a)` but correctly clears the `local` for `s`'s execution.
*
* @param local the [[Local]] that should be let-scoped around `a`
* @param s the underlying [[Stitch]] which will have the `local` set during it's evaluation
*/
def letClear[T](local: Local[_])(s: => Stitch[T]): Stitch[T] =
letClear(LocalLetClearer(local))(s)
/**
* [[Letter.let]] around the contained [[Stitch]] `s`
*
* This is equivalent to `Letter.let(local)(a)` but correctly applies the [[Letter.let]] to the `s`'s execution.
*
* This is used for let-scoping [[Local]]s which are private to a class and can only be accessed with their own
* let method instead of giving access to the underlying [[Local]]
*
* @note [[let]] applies to __only non-batched operations__,
* [[call]] and [[Group]]s do not have access to let-scoped values.
* To access a let-scoped value value within a [[call]], or [[Group]], access the value
* before making your [[call]] and add it to your input.
* For instance,`s.map(v => (v, local())).call(...)`
*
* @param letter [[Letter]] that let-scopes around a block of code
* @param value the value of the let-scoped [[Local]] within the execution of `s`
* @param s the underlying [[Stitch]] which will have the `local` set during it's evaluation
* @tparam L the type of the [[Local]] and it's value
*/
def let[T, L](letter: Letter[L])(value: L)(s: => Stitch[T]): Stitch[T] =
letter.let(value)(s) match { // let scope around evaluating `s` in case it's a `Const`
case CompletedStitch(s) => s
case s => Let(letter, value, s)
}