where
import Control.Concurrent.ParallelIO.Global (
- parallel,
+ parallelInterleaved,
stopGlobalPool )
import Control.Monad (unless)
import qualified Data.ByteString.Char8 as BS (
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