missionary.core/sp
Usage
(sp & body)
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
sp
completion is synchronous with finalbody
expression return- any
body
expression evaluation is synchronous with the return of the parking expression preceding it in program order, if it exists. Otherwise, it is synchronous withsp
spawn.