|
From: Frederik E. <fre...@a5...> - 2005-02-22 11:39:25
|
Please apply:
--- HSQL/src/HSQL.hsc 2005-02-22 03:37:23.000000000 -0800
+++ HSQL-modified/src/HSQL.hsc 2005-02-22 03:36:44.000000000 -0800
@@ -606,3 +606,22 @@
return (x:xs)
else return []
+-- | The 'collectRowsASync' function is just like collectRows, but it
+-- uses unsafeInterleaveIO to in the same manner as hGetContents to
+-- cause rows to be read asynchronously from the database in an
+-- "on-demand" fashion as list elements are accessed in the result.
+collectRowsAsync :: (Statement -> IO a) -> Statement -> IO [a]
+collectRowsAsync act stmt = loop
+ where
+ closeAndThrow e = do closeStatement stmt; throw e
+ loop = unsafeInterleaveIO $ (do
+ success <- catch (fetch stmt) closeAndThrow
+ if success
+ then do
+ x <- catch (act stmt) closeAndThrow
+ xs <- loop
+ return (x:xs)
+ else do
+ closeStatement stmt
+ return [])
+
Thanks,
Frederik
--
Frederik Eaton http://ofb.net/~frederik/
|