From 9da41d4e978f1a1ba403884088c55f3e22f856f4 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 1 Apr 2020 09:52:49 +1300 Subject: [PATCH] Request @import'd styles concurrently. --- src/Data/CSS/Preprocessor/Conditions.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Data/CSS/Preprocessor/Conditions.hs b/src/Data/CSS/Preprocessor/Conditions.hs index db84c90..61c514a 100644 --- a/src/Data/CSS/Preprocessor/Conditions.hs +++ b/src/Data/CSS/Preprocessor/Conditions.hs @@ -126,22 +126,20 @@ resolveImports self responses = self {rules = map resolveImport $ rules self} Internal cond body resolveImport x = x +-- | Evaluates a given "loader" to resolve any `@import` rules. loadImports :: PropertyParser p => (URI -> IO Text) -> (Text -> Query.Datum) -> (Token -> Query.Datum) -> ConditionalStyles p -> [URI] -> IO (ConditionalStyles p) loadImports loader vars evalToken self blocklist = do let imports = extractImports vars evalToken self - imported <- loadAll [url | url <- imports, url `notElem` blocklist] Nothing - return $ resolveImports self imported - where - loadAll urls Nothing = loadAll urls $ Just urls - loadAll (url:urls) (Just blocklist') = do + let urls = [url | url <- imports, url `notElem` blocklist] + imported <- forConcurrently urls $ \url -> do source <- loader url let parsed = parse self {rules = []} source - styles <- loadImports loader vars evalToken parsed (blocklist ++ blocklist') - rest <- loadAll urls $ Just blocklist' - return ((url, styles):rest) - loadAll [] _ = return [] + styles <- loadImports loader vars evalToken parsed (blocklist ++ urls) + return (url, styles) + return $ resolveImports self imported +-- | Evaluates any media queries, returning a new StyleSheet with the queued operations. resolve :: StyleSheet s => (Text -> Query.Datum) -> (Token -> Query.Datum) -> s -> ConditionalStyles p -> s resolve v t styles self = resolve' v t (reverse $ rules self) styles -- 2.30.2