purescript-pipes
purescript-pipes copied to clipboard
what's the story about parallelism?
Let's say you have Producer of some values, and want to run them in parallel. is there something you can do now to do that, if not what needs to be added to support such use case.
For example, this doesn't compile, as there is no instance of Monad for ParAff:
hoist sequential (traverse (hoist parallel) xs))
this worked for me:
mergeProducers :: forall t o a. Traversable t => t (Producer o Aff a) -> Producer o Aff (t a)
mergeProducers ps = do
var <- lift AV.empty
fib <- lift $ forkAff do
let consumer i = lift (AV.put i var) *> pure unit
x <- parTraverse (\p -> P.runEffectRec $ p //> consumer) ps
AV.kill (error "finished") var
pure x
let
loop = do
res <- lift $ try (AV.take var)
case res of
Left err -> lift $ joinFiber fib
Right e -> do
yield e
loop
loop