]> gitweb.michael.orlitzky.com - haeredes.git/blobdiff - src/Main.hs
Fix parallelization and bump to v0.3.0.
[haeredes.git] / src / Main.hs
index a5dc79466067f0dc70fc529169f55d111ae13b96..679a1ac1fe1d0dc3cf684420596676dde91e10e5 100644 (file)
@@ -2,7 +2,7 @@ module Main
 where
 
 import Control.Concurrent.ParallelIO.Global (
-  parallel,
+  parallelInterleaved,
   stopGlobalPool )
 import Control.Monad (unless)
 import qualified Data.ByteString.Char8 as BS (
@@ -113,10 +113,17 @@ main = do
                           NS{} -> lookupNS'
                           MX{} -> lookupMX'
 
-  _ <- withResolver rs $ \resolver -> do
-         -- Bad stuff happens if we try to run these lookups in parallel
-         -- instead of the reports.
-         records <- mapM (lookup_function resolver) nrml_domains
-         parallel (map (report nrml_delegates) records)
+  let lookup' d = withResolver rs $ \resolver ->
+                    lookup_function resolver d
+
+  -- Construct a list of [IO whatever]. The withResolver calls
+  -- are the ones that should be run in parallel.
+  let actions = map lookup' nrml_domains
+
+  -- Run the lookup actions in parallel.
+  results <- parallelInterleaved actions
+
+  -- Output the results.
+  _ <- mapM (report nrml_delegates) results
 
   stopGlobalPool