liveBook · Manning

Future?

As explained in Clojure: The Essential Reference

future? is a Clojure predicate that reports whether a value is a future reference.

future? is a Clojure predicate for determining whether a value is a future reference. Use it to identify the object returned by future or future-call before inspecting its state with future-done? or retrieving its result with deref. section 14.0 section 14.1

Distinguishing a future from its completion state

Create asynchronous work, then test its identity separately from whether its computation has finished: (def t2 (timer 10)) (future? t2) ;; true (future-done? t2) ;; false Here, future? reports what kind of value t2 is, while future-done? reports the computation's current state. After the work finishes, future-done? becomes true; the value remains a future reference.

(def t2 (timer 10)) ; #1

(future? t2) ; #2
;; true

(future-done? t2) ; #3
;; false

;; wait 10 seconds.

(future-done? t2) ; #4
;; true

Inspect the complete timed-future example, including creation, type checking, and completion checks. section 14.1

How Clojure: The Essential Reference covers it

How deep it goes
Defines the predicate's role and demonstrates its true result, but does not detail its implementation or false cases.
Examples
Uses a ten-second timer to compare future? with future-done? before and after asynchronous work completes.
What it assumes
Assumes familiarity with future references and introduces no separate concurrency model beyond their basic inspection.
What you can do after
Apply it via Clojure's concurrency API to distinguish future references from other values before checking completion.
How it connects
Connects future? with future, future-call, future-done?, deref, and asynchronous thread execution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.