Skip to content

Commit 61fcd61

Browse files
Update name of <!-no-throw to just <!
1 parent 08f3a7d commit 61fcd61

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docs/deferred.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ In this example, `c` is declared within a normal `let` binding, and as such we c
166166

167167
It can be helpful to think of `let-flow` as similar to Prismatic's [Graph](https://github.com/prismatic/plumbing#graph-the-functional-swiss-army-knife) library, except that the dependencies between values are inferred from the code, rather than explicitly specified. Comparisons to core.async's goroutines are less accurate, since `let-flow` allows for concurrent execution of independent paths within the bindings, whereas operations within a goroutine are inherently sequential.
168168

169-
### manifold.tsasvla
169+
### manifold.go-off
170170

171-
An alternate way to write code using deferreds is the macro `manifold.tsasvla/tsasvla`. This macro is an almost exact mirror of the `go` macro from [clojure/core.async](https://github.com/clojure/core.async), to the point where it actually utilizes the state machine functionality from core.async. In order to use this macro, `core.async` must be a dependency provided by the user. The main difference between `go` and `tsasvla`, besides tsasvla working with deferrables instead of core.async channels, is the `take` function being `<!?` instead of `<!`. The difference in function names is used to indicate exceptions behave the same as a non-async clojure block (i.e. are thrown) instead of silently swallowed & returning `nil`.
171+
An alternate way to write code using deferreds is the macro `manifold.go-off/go-off`. This macro is an almost exact mirror of the `go` macro from [clojure/core.async](https://github.com/clojure/core.async), to the point where it actually utilizes the state machine functionality from core.async. In order to use this macro, `core.async` must be a dependency provided by the user. The main difference between `go` and `go-off`, besides go-off working with deferrables instead of core.async channels, is the `take` function being `<!?` instead of `<!`. The difference in function names is used to indicate exceptions behave the same as a non-async clojure block (i.e. are thrown) instead of silently swallowed & returning `nil`.
172172

173173
The benefit of this macro over `let-flow` is that it gives complete control of when deferreds should be realized to the user of the macro, removing any potential surprises (especially around timeouts).
174174

175175
```clj
176-
@(tsasvla (+ (<!? (d/future 10))
176+
@(go-off (+ (<!? (d/future 10))
177177
(<!? (d/future 20)))) ;; ==> 30
178178
```
179179

@@ -182,7 +182,7 @@ The benefit of this macro over `let-flow` is that it gives complete control of w
182182
(catch Exception e
183183
"ERROR")))) ; ==> nil
184184

185-
@(tsasvla (try (<!? (d/future (/ 5 0)))
185+
@(go-off (try (<!? (d/future (/ 5 0)))
186186
(catch Exception e
187187
"ERROR"))) ; ==> "ERROR"
188188
```

src/manifold/go_off.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(d/success! d value)
1616
d))
1717

18-
(defn <!-no-throw
18+
(defn <!
1919
"takes value from deferred. Must be called inside a (go ...) block. Will
2020
return nil if closed. Will park if nothing is available. If an error
2121
is thrown inside the body, that error will be placed as the return value.
@@ -30,7 +30,7 @@
3030
Will park if nothing is available. If value that is returned is
3131
a Throwable, will re-throw."
3232
[port]
33-
`(let [r# (<!-no-throw ~port)]
33+
`(let [r# (<! ~port)]
3434
(if (instance? Throwable r#)
3535
;; this is a re-throw of the original throwable. the expectation is that
3636
;; it still will maintain the original stack trace
@@ -69,8 +69,8 @@
6969
nil))))))
7070

7171
(def async-custom-terminators
72-
{'manifold.go-off/<!-no-throw `manifold.go-off/take!
73-
:Return `return-deferred})
72+
{'manifold.go-off/<! `manifold.go-off/take!
73+
:Return `return-deferred})
7474

7575
(defmacro go-off-executor
7676
"Implementation of go-off that allows specifying executor. See docstring of go-off for usage."
@@ -94,7 +94,7 @@
9494
(defmacro go-off
9595
"Asynchronously executes the body on manifold's default executor, returning
9696
immediately to the calling thread. Additionally, any visible calls to <!?
97-
and <!-no-throw deferred operations within the body will block (if necessary)
97+
and <! deferred operations within the body will block (if necessary)
9898
by 'parking' the calling thread rather than tying up an OS thread.
9999
Upon completion of the operation, the body will be resumed.
100100

0 commit comments

Comments
 (0)