How to exponential back off with network requests

blov · · 384 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello everyone.</p> <p>I&#39;ve been writing some code that makes quick and dirty http requests and I realised my code is brittle because it will error if any request fails even once.</p> <p>What are some simple &#39;ways&#39; I can use exponential back off when making http requests? Can I do it with the standard lib (in an opaque manner)? Do I need a thin library? How have you done it in practice? </p> <p>Cheers!</p> <hr/>**评论:**<br/><br/>wilywes: <pre><p>My favourite library for this is <a href="https://github.com/sethgrid/pester" rel="nofollow">Pester </a>. There&#39;s a few others and it&#39;s simple enough that you could use the stdlib (pester has no dependencies). </p></pre>bmurphy1976: <pre><p>I wrote this a couple years back and we use it in some of our software. It doesn&#39;t support jitter or alternative backoff algorithms like the the library <a href="/u/wilywes" rel="nofollow">/u/wilywes</a> posted, but it&#39;s a bit more generic and useful in other situations:</p> <p><a href="https://github.com/mediafly/retry" rel="nofollow">https://github.com/mediafly/retry</a></p> <p>Could probably use some polish but it gets the job done. </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

384 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传