streamly
Copyright(c) 2022 Composewell Technologies
LicenseBSD-3-Clause
Maintainer[email protected]
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.Data.Stream.SVar

Description

Deprecated: This module will be removed in future.

Synopsis

Documentation

fromConsumer :: MonadAsync m => SVar Stream m a -> m Bool Source #

Poll for events sent by the fold consumer to the stream pusher. The fold consumer can send a Stop event or an exception. When a Stop is received this function returns True. If an exception is recieved then it throws the exception.

newFoldSVar :: MonadAsync m => State Stream m a -> (SerialT m a -> m b) -> m (SVar Stream m a) Source #

Create a Fold style SVar that runs a supplied fold function as the consumer. Any elements sent to the SVar are consumed by the supplied fold function.

newFoldSVarF :: forall m (t :: (Type -> Type) -> Type -> Type) a b. MonadAsync m => State t m a -> Fold m a b -> m (SVar t m a) Source #

Like newFoldSVar except that it uses a Fold instead of a fold function.

pushToFold :: MonadAsync m => SVar Stream m a -> a -> m Bool Source #

Push values from a stream to a fold worker via an SVar. Before pushing a value to the SVar it polls for events received from the fold consumer. If a stop event is received then it returns True otherwise false. Propagates exceptions received from the fold consumer.

teeToSVar :: forall (m :: Type -> Type) a. MonadAsync m => SVar Stream m a -> SerialT m a -> SerialT m a Source #

Tap a stream and send the elements to the specified SVar in addition to yielding them again. The SVar runs a fold consumer. Elements are tapped and sent to the SVar until the fold finishes. Any exceptions from the fold evaluation are propagated in the current thread.

------input stream---------output stream----->
                   /|\   |
        exceptions  |    |  input
                    |   \|/
                    ----SVar
                         |
                        Fold

toSVarParallel :: forall m (t :: (Type -> Type) -> Type -> Type) a. MonadAsync m => State t m a -> SVar t m a -> Stream m a -> m () Source #

Fold the supplied stream to the SVar asynchronously using Parallel concurrency style. {-# INLINE [1] toSVarParallel #-}

fromSVar :: forall (m :: Type -> Type) a. MonadAsync m => SVar Stream m a -> SerialT m a Source #

Generate a stream from an SVar. An unevaluated stream can be pushed to an SVar using toSVar. As we pull a stream from the SVar the input stream gets evaluated concurrently. The evaluation depends on the SVar style and the configuration parameters e.g. using the maxBuffer/maxThreads combinators.

fromSVarD :: forall (m :: Type -> Type) (t :: (Type -> Type) -> Type -> Type) a. MonadAsync m => SVar t m a -> Stream m a Source #

Like fromSVar but generates a StreamD style stream instead of CPS.

toSVar :: MonadAsync m => SVar SerialT m a -> SerialT m a -> m () Source #

Write a stream to an SVar in a non-blocking manner. The stream can then be read back from the SVar using fromSVar.