In the README, <?maybe is documented as take and throw errors, return value if it’s not a channel. The function itself does not mention the throwing errors part in it's docstring. If the function indeed was intended to throw in case of an error (which I actually use it for, cause that's great!) that might not be the consistent behavior of it.
In case you pass a chan, that's exactly what it does, cause that's what <? brings to the table with (throw-err).
In case you pass a promise, the (throw-err) functionality is missing. That could either be added in <?maybe, or in promise variant of <?, maybe <?p.
What do you think?
(defmacro <?maybe
"Tries to await for a value, first if checks if x is a channel, if so will read
on it; then it checks if it's a JS promise, if so will convert it to a channel
and read from it. Otherwise returns x as is."
[x]
`(let [res# ~x]
(cond
(chan? res#)
(<? res#)
(promise? res#)
(throw-err (<!p res#)) or (<?p res#)) <-----------
:else
res#))
In the README,
<?maybeis documented as take and throw errors, return value if it’s not a channel. The function itself does not mention the throwing errors part in it's docstring. If the function indeed was intended to throw in case of an error (which I actually use it for, cause that's great!) that might not be the consistent behavior of it.In case you pass a chan, that's exactly what it does, cause that's what
<?brings to the table with(throw-err).In case you pass a promise, the
(throw-err)functionality is missing. That could either be added in<?maybe, or in promise variant of<?, maybe<?p.What do you think?