Clojure core.async laying! against go block

I read this wonderful article about core.async here:

http://www.core-async.info/reference/primitives

I'm struggling to understand internal mechanics! and go. I understand that:

  • to put! is asynchronous and can receive a callback. This works well in simple scripts, but you can end the callback addon.
  • go fixes the callback addon and allows you to write asynchronous code in a synchronous style.
  • go uses a lightweight pool of threads and uses parking to enable concurrency.
  • go uses a state machine

I do not understand:

  • How to bet! achieve asynchrony? Does it also use thread pool?
  • Does! also uses parking?
  • What is the role of the state machine in the go block? Is that what parking allows?
  • Should I always try to use put! rather than go because it is cheaper? In this case, it means it is laid! achieve the same concurrency of kindness as go, and this transition is used when I want to talk about complex asynchronous code?

Thank you very much for shedding light on these secrets.

+4
source share
1 answer

If you want to understand how core.async channels work, there is no better source than the presentation of Rich Hickey EuroClojure 2014: Implementation information for core.async channels .

Regarding your specific questions:

  • put! , put (, + put!) , . , , ( ​​ 1024).

    , (1) put (2) false put! ( on-caller?, . put! docstring).

  • "" go go , , , . ( , , , go, GC'd, go GC'd.) . put! - (, , ), .

  • . go, , , " " (<!, >!, alt!).

  • , (. 1 ).

+7

Source: https://habr.com/ru/post/1628321/


All Articles