Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added const and null task functions #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion src/missionary/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,56 @@ Example :
([d x] (fn [s f] (Sleep/run d x s f))))


(defn
^{:static true
:arglists '([c task])
:doc "
Returns a task running given `task` but returning `c`.

If `task` succeeds, `const` completes with constant `c` regardless of `task` return value.

If `task` fails, `const` fails with this error.

Cancelling propogates to `task`.

Example :
```clojure
(? (const 42 (sleep 1000 1)))
#_=> 42 ;; 1 second later
```
"} const
[c task]
(fn [s f]
(task
(fn [_]
(try (s c)
(catch #?(:clj Throwable
:cljs :default) e
(f e)))) f)))


(defn
^{:static true
:arglists '([task])
:doc "
Returns a task running given `task` but returning nil.

If `task` succeeds, `null` completes with nil regardless of `task` return value.

If `task` fails, `const` fails with this error.

Cancelling propogates to `task`.

Example :
```clojure
(? (null (sleep 1000 1)))
#_=> nil ;; 1 second later
```
"} null
[task]
(const nil task))


(defn
^{:static true
:arglists '([f & tasks])
Expand Down Expand Up @@ -1089,4 +1139,5 @@ Example :
(reject [])]
(fn
([flow] (Propagator/flow {} nil run sub step done tick accept reject flow))
([sg flow] (Propagator/flow sg nil run sub step done tick accept reject flow))))))
([sg flow] (Propagator/flow sg nil run sub step done tick accept reject flow))))))