<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I have a <a href="https://hackage.haskell.org/package/conduit-parse-0.2.1.0/docs/Data-Conduit-Parser.html#t:ConduitParser" class="">ConduitParser</a> (a Sink with some parsing state) with a version of satisfy that can time out:<div class=""><br class=""></div><div class=""><div style="line-height: 15px;" class=""><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"><span style="color: #50fa7b;" class="">satisfy</span> <span style="color: #ff79c6;" class="">::</span> <span style="color: #8be9fd;font-style: italic;" class="">MonadIO</span> m <span style="color: #ff79c6;" class="">=></span> (a <span style="color: #ff79c6;" class="">-></span> <span style="color: #8be9fd;font-style: italic;" class="">Bool</span>) <span style="color: #ff79c6;" class="">-></span> <span style="color: #8be9fd;font-style: italic;" class="">ConduitParser</span> a m a</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);">satisfy pred <span style="color: #ff79c6;" class="">=</span> <span style="color: #ff79c6;" class="">do</span></div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> tId <span style="color: #ff79c6;" class=""><-</span> liftIO myThreadId</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> timeoutThread <span style="color: #ff79c6;" class=""><-</span> liftIO <span style="color: #ff79c6;" class="">$</span> forkIO <span style="color: #ff79c6;" class="">$</span> <span style="color: #ff79c6;" class="">do</span></div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> threadDelay <span style="color: #bd93f9;" class="">1000000</span></div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> throwTo tId <span style="color: #bd93f9;" class="">TimeoutException</span></div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> x <span style="color: #ff79c6;" class=""><-</span> await</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> liftIO <span style="color: #ff79c6;" class="">$</span> killThread timeoutThread</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span style="color: #ff79c6;" class="">if</span> pred x</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span style="color: #ff79c6;" class="">then</span> return x</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span style="color: #ff79c6;" class="">else</span> empty</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre;"><br class=""></div><div class="">However I would rather not deal with the risks involved with handling concurrency myself and use a system library like System.Timeout:</div><div class=""><br class=""></div><div class=""><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"><span class="" style="color: rgb(80, 250, 123);">satisfy</span> <span class="" style="color: rgb(255, 121, 198);">::</span> <span class="" style="color: rgb(139, 233, 253); font-style: italic;">MonadIO</span> m <span class="" style="color: rgb(255, 121, 198);">=></span> (a <span class="" style="color: rgb(255, 121, 198);">-></span> <span class="" style="color: rgb(139, 233, 253); font-style: italic;">Bool</span>) <span class="" style="color: rgb(255, 121, 198);">-></span> <span class="" style="color: rgb(139, 233, 253); font-style: italic;">ConduitParser</span> a m a</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);">satisfy pred <span class="" style="color: rgb(255, 121, 198);">=</span> <span class="" style="color: rgb(255, 121, 198);">do</span></div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> x <span class="" style="color: rgb(255, 121, 198);"><-</span> timeout <span style="caret-color: rgb(189, 147, 249); color: rgb(189, 147, 249);" class="">1000000</span> await</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span class="" style="color: rgb(255, 121, 198);">if</span> pred x</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span class="" style="color: rgb(255, 121, 198);">then</span> return x</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);"> <span class="" style="color: rgb(255, 121, 198);">else</span> empty</div><div class="" style="color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre;"><br class=""></div><div class=""><div class="" style="caret-color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; white-space: normal;" class="">This doesn’t work though since I need to be able to both lift and unlift <span style="background-color: rgb(40, 42, 54); color: rgb(248, 248, 242); font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace; font-size: 11px; white-space: pre;" class="">await</span> from </span><font color="#f8f8f2" face="SF Mono, Menlo, Monaco, Courier New, monospace" class=""><span style="font-size: 11px; white-space: pre; background-color: rgb(40, 42, 54);" class="">IO</span></font>, and ConduitParser lies on top of ConduitT, which is <a href="https://github.com/fpco/unliftio#limitations" class="">one of the types of monads that UnliftIO cannot be an instance of</a>. Are there any better approaches to this?</div><a href="https://github.com/fpco/unliftio#limitations" class=""></a><a href="https://github.com/fpco/unliftio#limitations" class=""></a><a href="https://github.com/fpco/unliftio#limitations" class=""></a></div></div></div></div></body></html>