- withResolver rs $ \resolver -> do
- -- Construst a list of [IO (Address, Bool)]
- let actions = map (validate resolver accept_a) nonempty_addresses
- -- And compute them in parallel.
- results <- parallel actions
- stopGlobalPool
- -- Find the pairs with a True in the second position.
- let good_pairs = filter snd results
- -- And output the results.
- mapM_ ((append_handle_with_newline output_handle) . fst) good_pairs
-
- -- Clean up. It's safe to try to close stdout.
- hFlush output_handle
- hClose output_handle
+ let validate' addr = withResolver rs $ \resolver ->
+ validate resolver accept_a rfc5322 addr
+
+ -- Construct a list of [IO (Address, Bool)]. The withResolver calls
+ -- are the ones that should be run in parallel.
+ let actions = map validate' nonempty_addresses
+
+ -- Run the lookup actions in parallel.
+ results <- parallelInterleaved actions
+
+ -- Filter the bad ones.
+ let valid_results = filter snd results
+
+ -- Output the results.
+ let valid_addresses = map fst valid_results
+ mapM_ (BS.hPutStrLn stdout) valid_addresses
+
+ stopGlobalPool
+ hFlush stdout