Re: Idiomatic way to return a single value from an async function

2014-11-11 Thread Stuart Sierra
Similarly, but I would be explicit about the different arities, to avoid the intermediate sequence created by [arg & [option]] and to get errors if there are too many arguments. (defn foo ([input] (foo input (chan 1)) ([input ch] ... do something and put to ch ...)) If your function ca

Re: Idiomatic way to return a single value from an async function

2014-11-11 Thread Thomas Heller
Hey, what is your definition of an async function in Clojure? I imagine something something that starts a (go ...), if appropriate you can use the result of (go ...) as the result of the function since that is a channel that will receive the return value of the go block when it dies. (defn sta

Re: Idiomatic way to return a single value from an async function

2014-11-11 Thread László Török
+1, this is mostly what we resort to. (defn some-async-func [param-a param-b & [out-chan]] (let [ch (or out-chan (chan)] ... ) 2014-11-11 8:53 GMT+00:00 Daniel Kersten : > You could do both: > > Make the channel optional. If it's provided, use that and return it. If > it's not provided,

Re: Idiomatic way to return a single value from an async function

2014-11-11 Thread Daniel Kersten
You could do both: Make the channel optional. If it's provided, use that and return it. If it's not provided, create a new one and use and return that. This way the caller gets to decide which they wish to use based on who the owner of the channel should be or if the channel should be reused else