Skip to content

Instantly share code, notes, and snippets.

@lukehoersten
Last active December 31, 2015 00:09
Show Gist options
  • Save lukehoersten/7905146 to your computer and use it in GitHub Desktop.
Save lukehoersten/7905146 to your computer and use it in GitHub Desktop.
-- Uncaught exception: 'getPromise: dereferenced empty key (id 0)'
manyWithSplices :: Monad n
=> Splice n
-- ^ Splice to be run
-> Splices (RuntimeSplice n a -> Splice n)
-- ^ Splices to be bound to each runtime data first
-> RuntimeSplice n [a]
-- ^ Runtime data needed by the above splices
-> Splice n
manyWithSplices splice splices runtimeAction =
manyWithSplices' splice noSplices splices runtimeAction
manyWithSplices' :: Monad n
=> Splice n
-- ^ Splice to be run
-> Splices (RuntimeSplice n [a] -> Splice n)
-- ^ Splices to be bound to all runtime data first
-> Splices (RuntimeSplice n a -> Splice n)
-- ^ Splices to be bound to each runtime data first
-> RuntimeSplice n [a]
-- ^ Runtime data needed by the above splices
-> Splice n
manyWithSplices' splice listSplices singleSplices runtimeAction = do
p <- newEmptyPromise
ps <- newEmptyPromise
let splices' = mapS ($ getPromise p) singleSplices <> (listSplices $$ getPromise ps)
chunks <- withLocalSplices splices' noSplices splice
return $ yieldRuntime $ do
items <- runtimeAction
res' <- putPromise ps items >> codeGen chunks
res <- forM items $ \item -> putPromise p item >> codeGen chunks
return . mconcat $ res' : res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment