Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add mapCassandra to be able to run cassandra actions in parallel

  • Loading branch information...
commit 2592befcab9aa9c6f6897614527ac845e65e297a 1 parent f20baa7
@ozataman ozataman authored
View
3  cassy.cabal
@@ -1,5 +1,5 @@
Name: cassy
-Version: 0.4.1.1
+Version: 0.4.2.0
Synopsis: A high level driver for the Cassandra datastore
License: BSD3
License-file: LICENSE
@@ -75,6 +75,7 @@ Library
, cassandra-thrift >= 0.8
, resource-pool
, data-default
+ , async
test-suite test
View
12 src/Database/Cassandra/Basic.hs
@@ -24,6 +24,7 @@ module Database.Cassandra.Basic
, MonadCassandra (..)
, Cas (..)
, runCas
+ , mapCassandra
-- * Cassandra Operations
, getCol
@@ -81,6 +82,7 @@ module Database.Cassandra.Basic
-------------------------------------------------------------------------------
import Control.Applicative
+import Control.Concurrent.Async
import Control.Exception
import Control.Monad
import Control.Monad.Reader
@@ -88,6 +90,7 @@ import Data.ByteString.Lazy (ByteString)
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
+import Data.Traversable (Traversable)
import qualified Database.Cassandra.Thrift.Cassandra_Client as C
import Database.Cassandra.Thrift.Cassandra_Types
(ConsistencyLevel (..))
@@ -133,6 +136,15 @@ class (MonadIO m) => MonadCassandra m where
-------------------------------------------------------------------------------
+-- | Run a list of cassandra computations in parallel using the async library
+mapCassandra :: (Traversable t, MonadCassandra m) => t (Cas b) -> m (t b)
+mapCassandra ms = do
+ cp <- getCassandraPool
+ let f m = runCas cp m
+ liftIO $ mapConcurrently f ms
+
+
+-------------------------------------------------------------------------------
withCassandraPool :: MonadCassandra m => (Cassandra -> IO b) -> m b
withCassandraPool f = do
p <- getCassandraPool
View
1  src/Database/Cassandra/JSON.hs
@@ -36,6 +36,7 @@ module Database.Cassandra.JSON
, MonadCassandra (..)
, Cas
, runCas
+ , mapCassandra
-- * Cassandra Operations
, get
Please sign in to comment.
Something went wrong with that request. Please try again.