conduit-algorithms-0.0.8.0: Conduit-based algorithms

Copyright2013-2018 Luis Pedro Coelho
LicenseMIT
Maintainerluis@luispedro.org
Safe HaskellNone
LanguageHaskell2010

Data.Conduit.Algorithms.Async

Description

Higher level async processing interfaces.

Synopsis

Documentation

conduitPossiblyCompressedFile :: (MonadUnliftIO m, MonadResource m, MonadThrow m) => FilePath -> Source m ByteString Source #

If the filename indicates a gzipped file (or, on Unix, also a bz2 file), then it reads it and uncompresses it.

On Windows, attempting to read from a bzip2 file, results in error.

For the case of gzip, asyncGzipFromFile is used.

asyncMapC Source #

Arguments

:: (MonadIO m, NFData b) 
=> Int

Maximum number of worker threads

-> (a -> b)

Function to execute

-> Conduit a m b 

This is like map, except that each element is processed in a separate thread (up to maxThreads can be queued up at any one time). Results are evaluated to normal form (not weak-head normal form!, i.e., the structure is deeply evaluated) to ensure that the computation is fully evaluated in the worker thread.

Note that there is some overhead in threading. It is often a good idea to build larger chunks of input before passing it to asyncMapC to amortize the costs. That is, when f is not a lot of work, instead of asyncMapC f, it is sometimes better to do

   CC.conduitVector 4096 .| asyncMapC (V.map f) .| CC.concat

where CC refers to Combinators

See unorderedAsyncMapC

asyncMapEitherC :: forall a m b e. (MonadIO m, NFData b, NFData e, MonadError e m) => Int -> (a -> Either e b) -> Conduit a m b Source #

asyncMapC with error handling. The inner function can now return an error (as a Left). When the first error is seen, it throwErrors in the main monad. Note that f may be evaluated for arguments beyond the first error (as some threads may be running in the background and already processing elements after the first error).

See asyncMapC

asyncGzipTo :: forall m. (MonadIO m, MonadUnliftIO m) => Handle -> Sink ByteString m () Source #

A simple sink which performs gzip compression in a separate thread and writes the results to h.

See also asyncGzipToFile

asyncGzipToFile :: forall m. (MonadResource m, MonadUnliftIO m) => FilePath -> Sink ByteString m () Source #

Compresses the output and writes to the given file with compression being performed in a separate thread.

See also asyncGzipTo

asyncGzipFrom :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Handle -> Source m ByteString Source #

A source which produces the ungzipped content from the the given handle. Note that this "reads ahead" so if you do not use all the input, the Handle will probably be left at an undefined position in the file.

See also asyncGzipFromFile

asyncGzipFromFile :: forall m. (MonadResource m, MonadUnliftIO m) => FilePath -> Source m ByteString Source #

Open and read a gzip file with the uncompression being performed in a separate thread.

See also asyncGzipFrom

asyncBzip2To :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Handle -> Sink ByteString m () Source #

A simple sink which performs bzip2 compression in a separate thread and writes the results to h.

See also asyncGzipToFile

asyncBzip2ToFile :: forall m. (MonadResource m, MonadUnliftIO m) => FilePath -> Sink ByteString m () Source #

Compresses the output and writes to the given file with compression being performed in a separate thread.

See also asyncGzipTo

asyncBzip2From :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Handle -> Source m ByteString Source #

A source which produces the bzipped2 content from the the given handle. Note that this "reads ahead" so if you do not use all the input, the Handle will probably be left at an undefined position in the file.

See also asyncGzipFromFile

asyncBzip2FromFile :: forall m. (MonadResource m, MonadUnliftIO m) => FilePath -> Source m ByteString Source #

Open and read a bzip2 file with the uncompression being performed in a separate thread.

See also asyncGzipFrom

asyncXzTo :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m) => Handle -> Sink ByteString m () Source #

A simple sink which performs lzma/xz compression in a separate thread and writes the results to h.

See also asyncGzipToFile

asyncXzToFile :: forall m. (MonadResource m, MonadUnliftIO m) => FilePath -> Sink ByteString m () Source #

Compresses the output and writes to the given file with compression being performed in a separate thread.

See also asyncGzipTo

asyncXzFrom :: forall m. (MonadIO m, MonadResource m, MonadUnliftIO m, MonadThrow m) => Handle -> Source m ByteString Source #

A source which produces the unxzipped content from the the given handle. Note that this "reads ahead" so if you do not use all the input, the Handle will probably be left at an undefined position in the file.

See also asyncGzipFromFile

asyncXzFromFile :: forall m. (MonadResource m, MonadUnliftIO m, MonadThrow m) => FilePath -> Source m ByteString Source #

Open and read a lzma/xz file with the uncompression being performed in a separate thread.

See also asyncXzFrom

unorderedAsyncMapC Source #

Arguments

:: (MonadIO m, NFData b) 
=> Int

Maximum number of worker threads

-> (a -> b)

Function to execute

-> Conduit a m b 

A version of asyncMapC which can reorder results in the stream

If the order of the results is not important, this function can lead to a better use of resources if some of the chunks take longer to complete.

See asyncMapC