class

JoobQ::BackgroundLoop

Inherits Reference < Object

A cancellable periodic fiber.

stop wakes a loop that is sleeping between iterations and waits for the fiber to exit, so no iteration runs after stop has returned. Flag-only stops are racy once fibers may run on other threads (Crystal's default execution context is parallel).

Every start owns its own run state, so a restart after a stop that timed out can never leave two live fibers sharing one flag.

Constants

ERROR_BACKOFF = 5.seconds
Log = ::Log.for("BACKGROUND_LOOP")

Constructors

new(name : String, error_backoff : Time::Span = ERROR_BACKOFF)
Source

Instance methods

running?
Source
start

Starts the loop. The block runs one iteration and returns how long to sleep before the next one. Returns false when already running.

Source
stop(wait : Time::Span = 5.seconds) : Bool

Stops the loop and waits (up to wait) for its fiber to exit. Returns false when the loop was not running. When called from inside the loop body itself it does not wait (a fiber cannot join itself).

Source