Home

missionary.core/sp

Usage

A macro operator returning a task evaluating body, in an implicit do, in a context supporting asynchronous parking and interruption checking. sp process completes with the evaluation result, or crashes if an exception is thrown. Cancelling sp process interrupts the evaluation context.

Example : a task performing a synchronous effect.

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

(def prn-foo (m/sp (prn :foo)))

(m/? prn-foo)   ;; :foo
:= nil

Example : transform the result of task.

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

(defn map-name [task]
  (m/sp (name (m/? task))))

(m/? (map-name (m/sleep 1000 :foo)))
:= "foo"

Example : recover from a task failure.

(require '[missionary.core :as m])
(import 'java.io.IOException)

(defn recover-io [task]
  (m/sp (try (m/? task)
             (catch IOException _
               :io-failure))))

(m/? (recover-io (m/via m/blk (slurp "https://clojur.org"))))
:= :io-failure

Synchronicity

See also