<p>I just watched this <a href="https://www.youtube.com/watch?v=HQtLRqqB-Kk" rel="nofollow">talk</a> by
Andrew Gerrand about Cuddle. There's a bit at around
<a href="https://youtu.be/HQtLRqqB-Kk?t=14m14s" rel="nofollow">14:14</a> where he lost me. The slides in
question are <a href="http://cuddle.googlecode.com/hg/talk/index.html#slide-11" rel="nofollow">here</a>
and <a href="http://cuddle.googlecode.com/hg/talk/index.html#slide-12" rel="nofollow">here</a>.</p>
<p>Is there something inherent to closures that make the operation safe and not
racey?</p>
<hr/>**评论:**<br/><br/>TheMerovius: <pre><p>No, it's just an API thing. Instead of giving you a transaction-type, with Rollback and Commit, the API just takes a func(appengine.Context) error, and basically does</p>
<pre><code>func RunInTransaction(c appengine.Context, fn func(appengine.Context) error) {
tx := db.Begin()
if err := fn(c); err != nil {
tx.Rollback()
} else {
tx.Commit()
}
}
</code></pre></pre>alexwhoizzle: <pre><p>Correct. Its not that the closure itself adds transactional support. Its the call to datastore.RunInTransaction that does. You need the closure to pass in your needed datastore.Get call which you want done inside of a transaction.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传