Permalink
Browse files

Add mapCassandra to be able to run cassandra actions in parallel

  • Loading branch information...
ozataman committed Dec 12, 2012
1 parent f20baa7 commit 2592befcab9aa9c6f6897614527ac845e65e297a
Showing with 15 additions and 1 deletion.
  1. +2 −1 cassy.cabal
  2. +12 −0 src/Database/Cassandra/Basic.hs
  3. +1 −0 src/Database/Cassandra/JSON.hs
View
@@ -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
@@ -24,6 +24,7 @@ module Database.Cassandra.Basic
, MonadCassandra (..)
, Cas (..)
, runCas
+ , mapCassandra
-- * Cassandra Operations
, getCol
@@ -81,13 +82,15 @@ module Database.Cassandra.Basic
-------------------------------------------------------------------------------
import Control.Applicative
+import Control.Concurrent.Async
import Control.Exception
import Control.Monad
import Control.Monad.Reader
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 (..))
@@ -132,6 +135,15 @@ class (MonadIO m) => MonadCassandra m where
getCassandraPool :: m CPool
+-------------------------------------------------------------------------------
+-- | 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
@@ -36,6 +36,7 @@ module Database.Cassandra.JSON
, MonadCassandra (..)
, Cas
, runCas
+ , mapCassandra
-- * Cassandra Operations
, get

0 comments on commit 2592bef

Please sign in to comment.