简体   繁体   English

clojure.core.async / ALTS! -保证只操作一个通道?

[英]clojure.core.async/alts!! - Guaranteed only one channel is operated on?

When alts!! alts!! or alts! alts! is called, is it guaranteed that only one of the ports are taken from or put into? 称为,是否可以保证仅取放一个端口或将其中一个端口放进去?

(let [[value channel] (alts!! [c1 c2 c3 [1 c4]])]
   (cond (= channel c1)
         ; at this point, is it guaranteed that alts!!
         ; did not take from c2 and c3, and did not call (>!! c4 1)? 
         (do-something)))

I can't find anything relevant about this in the docs. 我在文档中找不到与此相关的任何内容。 I am guessing it is undefined? 我猜它是不确定的?

According to alts! 根据alts! 's docstring the function " Completes at most one of several channel operations. [...] ". 文档字符串函数“ 最多完成几个通道操作之一。[...] ”。

This means that only one or zero (ie it will park) operations will be done on the ports when the function is called. 这意味着在调用该函数时,只会在端口上执行一次或零次操作(即它将停放)。 Which operation is non-deterministic, as described in the docstring: " Unless the :priority option is true, if more than one port operation is ready a non-deterministic choice will be made ". 如文档字符串中所述,哪种操作是不确定的:“ 除非:priority选项为true,否则如果准备好多个端口操作,则将做出不确定的选择 ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM