Skip to main content

async

Jump to function (1)

async/delay#

(delay seconds)

Suspends execution for seconds. Accepts any number (int, float, or Ratio); sub-second precision such as 0.05 is supported.

At the top level this behaves like php/sleep / php/usleep: it blocks the script for the given duration. Inside an async/future body (or any AMPHP fiber context) it suspends the fiber, not the whole process, so other concurrent fibers keep running and the delay is cancellable via future-cancel.

phel.async/delay is not the Clojure clojure.core/delay. The Clojure form returns a lazy thunk that caches the result of evaluating body on first deref; Phel's version is a sleep primitive. They are unrelated. Reach for phel.async/delay when you want to throttle, time out, or compose with future / pmap; reach for php/sleep when you just want a blocking pause and don't care about fiber semantics.

Example:

(delay 0.5) ; suspends current fiber for 500ms
  (async (delay 1.0) :done) ; => future that resolves after 1s
  (delay (/ 1 1000)) ; ratio collapses to a float