Clojure 的 STM 值历史记录可以访问吗?
鉴于 STM 保存了 10 个 refs、agents 等值的历史记录,这些值可以读取吗?
原因是,我正在更新大量代理,并且需要保留值的历史记录。如果 STM 已经保留了它们,我宁愿直接使用它们。我在 API 中找不到看起来像是从 STM 历史记录中读取值的函数,所以我猜不是,我也无法在 java 源代码中找到任何方法,但也许我看起来不对。
Given that the STM holds a history of say 10 values of refs, agents etc, can those values be read ?
The reason is, I'm updating a load of agents and I need to keep a history of values. If the STM is keeping them already, I'd rather just use them. I can't find functions in the API that look like they read values from the STM history so I guess not, nor can I find any methods in the java source code, but maybe I didn't look right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法直接访问值的 stm 历史记录。但是您可以使用 add-watch 记录值的历史记录:
每次更新
a
(stm 事务提交)时,旧值都会被转换到a-history
中保存的序列上。如果您想访问所有中间值,即使对于回滚事务,您也可以在事务期间将这些值发送给代理:
事务完成后,代理的所有更改
r -history
将被执行。You cannot access the stm history of values directly. But you can make use of add-watch to record the history of values:
Every time
a
is updated (the stm transaction commits) the old value will be conjed onto the sequence that is held ina-history
.If you want to get access to all the intermediary values, even for rolled back transactions you can send the values to an agent during the transaction:
After the transaction finished, all changes to the agent
r-history
will be executed.