Thank you very much for the clarification and your incredibly fast reply :)

Leon.

On Thursday, October 31, 2013 3:16:22 PM UTC+1, tbc++ wrote:
>
> Yes, returning a value that will be created in some sort of async fashion, 
> directly from a function is not idiomatic. Instead, you should be returning 
> channels and calling <! on them. Inside your functions you can use put! to 
> keep from having to decide between >! and >!!. As an example, here is how 
> you would use http-kit's http async client from core.async:
>
> (require '[org.httpkit.client :as http])
>
> (defn http-get [url]
>   (let [c (chan)]
>     (http/get url
>               (fn [r] (put! c r)))
>     c))
>
> Now you can do both: 
> (<!! (http-get "www.google.com"))
>
> (go (<! (http-get "www.google.com")))
>
>
>
> Timothy Baldridge
>
>
>
> On Thu, Oct 31, 2013 at 4:34 AM, Leon Grapenthin 
> <[email protected]<javascript:>
> > wrote:
>
>> Hello everyone,
>> (I am posting here because I could not find a dedicated core.async group)
>>
>> recently I made a rather obscure bug-report (ASYNC-29). As a comment Rich 
>> Hickey stated that <!! and >!! should not be used in library code. I can 
>> now reproduce the same problem without <!!/>!! by simply derefing 50 
>> undelivered promises in dedicated go-blocks (dotimes [_ 50] (go 
>> @(promise))). After that it is not possible to take from channels inside 
>> go-blocks. 
>>
>> Now I can imagine that using promises in go-blocks is not exactly doing 
>> what they are designed for. I suppose that using promises within go is not 
>> supported. However I wonder what my options as a library creator are when I 
>> want to write a function that is designed to wait until it has taken a 
>> value from a channel. The only way I can see is to write a macro instead of 
>> a function, two versions. One using <!, designed for use in go-blocks, one 
>> using <!!, designed for use outside of go blocks. Otherwise, I don't see 
>> any possible way to get a value from a channel and returning it. Or am I 
>> missing something?
>>
>> Is it simply unidiomatic to return a value from a channel from a function 
>> body? 
>>
>> Best regards,
>>  Leon.
>>
>> -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
> “One of the main causes of the fall of the Roman Empire was that–lacking 
> zero–they had no way to indicate successful termination of their C 
> programs.”
> (Robert Firth) 
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to