Home

missionary.core/dfv

Usage

Description

A port constructor defining a dataflow variable. A variable is initially empty and can be assigned to an arbitrary value later, at most once. Dereferencing a variable is an asynchronous effect completing on assignment.

Note : dfv can be seen as an asynchronous version of clojure.core/promise.

Examples

Dataflow variables can be used for oz-style declarative concurrency

(require '[missionary.core :as m])

(def x (m/dfv))
(def y (m/dfv))
(def z (m/dfv))

(def main
  (m/join (constantly nil)
    (m/sp (prn :> (z (+ (m/? x) (m/? y)))))
    (m/sp (x 40))
    (m/sp (y 2))))

(def ps (main #(prn :success %) #(prn :failure %)))
:> 42
:success nil

Synchronicity