GlobalSoftDeadline

GlobalSoftDeadline is an endomorphic stage that passes values through as long as a wall-clock deadline has not elapsed. The deadline is measured from the moment the instance is created: the current time is captured once at construction and never updated. On each invocation, if the elapsed time is less than duration, the stage yields Status.Success; otherwise it yields Status.Complete.

The deadline is global in the sense that it is fixed at construction. This contrasts with LocalSoftDeadline, which resets its clock after each evolution transition.

The factory has three overloads:

import h8io.stages.*
import h8io.stages.std.*
var t = 0L
// t: Long = 0L
val deadline = GlobalSoftDeadline[String](() => t, 3L)
// deadline: GlobalSoftDeadline[String] = <function1>

deadline("first")
// res0: Yield.Some[String, String, Nothing] = Some(
//   out = "first",
//   status = Success,
//   evolution = ConstEvolution(
//     stage = <function1>,
//     _dispose = h8io.stages.base.ConstEvolution$$$Lambda$14325/0x00007f2c92621d60@4bfbbb9
//   )
// )
t = 4L
deadline("second")
// res2: Yield.Some[String, String, Nothing] = Some(
//   out = "second",
//   status = Complete(),
//   evolution = ConstEvolution(
//     stage = <function1>,
//     _dispose = h8io.stages.base.ConstEvolution$$$Lambda$14325/0x00007f2c92621d60@4bfbbb9
//   )
// )

The first call sees elapsed time 0 < 3 and yields Status.Success; after advancing the clock past the budget, the second call sees elapsed time 4 ≥ 3 and yields Status.Complete.