如何创建不断重试的枚举器
我正在使用 John Millikin 的枚举器包,并尝试创建大致相当于 Data.Enumerator.Binary.enumHandle 的东西,只不过它连接套接字本身,然后尝试枚举生成的句柄。困难在于连接不可靠,我希望它在出现问题时重新连接并恢复枚举。
我通常期望 Enumerator 是它自己有意义的 Monad 实例,但由于它是函数的类型别名,因此它的 Monadic 行为只是其输入步骤的读取器,这在这里似乎没有多大用处。我尝试使用 catchError 将一些东西放在一起,不断循环枚举器,但它没有达到我的预期,而且我无法弄清楚它在做什么,所以我想知道是否有人可以提出一个很好的惯用方法来解决这个问题。我对解决方案的框架很满意,因为显然我省略了许多细节。
有什么想法吗?
I'm using John Millikin's enumerator package and am trying to create something roughly equivalent to Data.Enumerator.Binary.enumHandle
, except it connects the socket itself, then tries to enumerate the resulting handle. The difficulty comes from the fact that the connection is unreliable, and I'd like it to reconnect and resume enumerating if something goes wrong.
I'd normally expect Enumerator to be its own meaningful Monad instance, but since it's a type alias for a function, monadic behavior on it is just a reader of its input step, which doesn't appear to be much use here. I tried to throw something together that just kept looping the Enumerator, using catchError
, but it didn't do what I expected and I couldn't figure out what it was doing, so I was wondering if anyone could suggest a nice idiomatic approach to this. I'm fine with just a skeleton of a solution, since there are obviously many details that I've omitted.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能必须自己写。我不认为它是在任何地方预定义的。然而,这并不困难:
这应该可行。
You probably have to write that yourself. I don't think it's predefined anywhere. However, it's not that difficult:
That should work.
从稍微高一点的角度来看,如果您正在使用套接字进行操作,尤其是可能不可靠的套接字,我不推荐 zeromq 足够高。
From a slightly higher view point, if you're doing stuff with sockets, especially potentially unreliable ones, I can't recommend zeromq highly enough.