-__-&quot; hehe why did I not let Hayoo or Hoogle help me there *sigh*<br><br>Thanks!!<br><br><div class="gmail_quote">2009/5/31 Sterling Clover <span dir="ltr">&lt;<a href="mailto:s.clover@gmail.com">s.clover@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The proper way is just to wrap System.Timeout, which does some rather clever things with regards to exception semantics. The code for it is a joy to read, by the way.<br>


<br>
--S.<div><div></div><div class="h5"><br>
<br>
On May 30, 2009, at 5:36 PM, Sebastian Sylvan wrote:<br>
<br>
</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
<br>
<br>
On Sat, May 30, 2009 at 10:32 PM, Cetin Sert &lt;<a href="mailto:cetin.sert@gmail.com" target="_blank">cetin.sert@gmail.com</a>&gt; wrote:<br>
Thank you for your reply, I&#39;d come up with the following:<br>
<br>
timed :: Int → IO a → b → IO (Either b a)<br>
timed max act def = do<br>
<br>
  r ← new<br>
<br>
  t ← forkIO $ do<br>
    a ← act<br>
    r ≔ Right a<br>
<br>
  s ← forkIO $ do<br>
    wait max<br>
    e ← em r<br>
    case e of<br>
      True  → do<br>
        kill t<br>
        r ≔ Left def<br>
<br>
      False → return ()<br>
<br>
  takeMVar r<br>
<br>
---------------------<br>
<br>
*Network.Port.Scan&gt; timed 500 (wait 50000 &gt;&gt; return 0) &#39;x&#39;<br>
Left &#39;x&#39;<br>
*Network.Port.Scan&gt; timed 500000 (wait 50000 &gt;&gt; return 0) &#39;x&#39;<br>
Right 0<br>
<br>
---------------------<br>
<br>
before reading your reply:<br>
<br>
<br>
timed timeout act fallback = do<br>
   res &lt;- newEmptyMVar<br>
   tid &lt;- forkIO $ act &gt;&gt;= writeMVar res<br>
   threadDelay timeout<br>
   stillRunning &lt;- isEmptyMVar res<br>
   if stillRunning then killThread tid &gt;&gt; return fallback else takeMVar res<br>
<br>
---------------------<br>
<br>
*Network.Port.Scan&gt; timed2 500 (wait 50000 &gt;&gt; return 0) &#39;x&#39;<br>
<br>
&lt;interactive&gt;:1:33:<br>
    No instance for (Num Char)<br>
      arising from the literal `0&#39; at &lt;interactive&gt;:1:33<br>
    Possible fix: add an instance declaration for (Num Char)<br>
    In the first argument of `return&#39;, namely `0&#39;<br>
    In the second argument of `(&gt;&gt;)&#39;, namely `return 0&#39;<br>
    In the second argument of `timed2&#39;, namely<br>
        `(wait 50000 &gt;&gt; return 0)&#39;<br>
<br>
<br>
Right, I forgot about the &quot;Either&quot; bit so you&#39;d have to make sure the action&#39;s result and the default has the same type (or modify it to return an Either).<br>
<br>
<br>
<br>
-- <br>
Sebastian Sylvan<br>
+44(0)7857-300802<br>
UIN: 44640862<br></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>