packages feed

foreign-store 0.1 → 0.2

raw patch · 2 files changed

+18/−6 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Foreign.Store: data Store a
+ Foreign.Store: StoreNotFound :: StoreException
+ Foreign.Store: data StoreException
+ Foreign.Store: newtype Store a

Files

foreign-store.cabal view
@@ -1,6 +1,6 @@ name:                foreign-store-version:             0.1-synopsis:            Store a stable pointer in a foreign context to be retrieved later. Persists through GHCi reloads.+version:             0.2+synopsis:            Store a stable pointer in a foreign context to be retrieved later. description:         Store a stable pointer in a foreign context to be retrieved later. Persists through GHCi reloads. license:             BSD3 license-file:        LICENSE
src/Foreign/Store.hs view
@@ -13,7 +13,8 @@   ,deleteStore   ,storeAction   ,withStore-  ,Store(..))+  ,Store(..)+  ,StoreException(..))   where  import Control.Exception@@ -30,11 +31,13 @@ instance Exception StoreException  -- | A hideously unsafe store. Only for use if you are suave.-data Store a =+newtype Store a =   Store Word32   deriving (Show,Eq)  -- | Lookup from the store if an index is allocated.+--+-- Not thread-safe. lookupStore :: Word32 -> IO (Maybe (Store a)) lookupStore i =   do r <- x_lookup i@@ -45,6 +48,7 @@ -- | Allocates or finds an unallocated store. The index is random. The -- internal vector of stores grows in size. When stores are deleted -- the vector does not shrink, but old slots are re-used.+-- -- Not thread-safe. newStore :: a -> IO (Store a) newStore a =@@ -56,6 +60,7 @@ -- creates one and resizes the store vector to fit. If there is -- already a store at the given index, deletes that store with -- 'deleteStore' before replacing it.+-- -- Not thread-safe. writeStore :: Store a -> a -> IO () writeStore (Store i) a =@@ -67,6 +72,7 @@  -- | Read from the store. If the store has been deleted or is -- unallocated, this will throw an exception.+-- -- Not thread-safe. readStore :: Store a -> IO a readStore (Store i) =@@ -76,7 +82,9 @@         else deRefStablePtr sptr  -- | Frees the stable pointer for GC and frees up the slot in the--- store. Deleting an already deleted store is a no-op.+-- store. Deleting an already deleted store is a no-op. But remember+-- that store numbers are re-used.+-- -- Not thread-safe. deleteStore :: Store a -> IO () deleteStore (Store i) = do@@ -87,13 +95,17 @@              x_delete i  -- | Run the action and store the result.+--+-- Not thread-safe. storeAction :: Store a -> IO a -> IO a storeAction s m =   do v <- m      writeStore s v      return v --- | Run the action and store the result.+-- | Run the action with the value in the store.+--+-- Not thread-safe. withStore :: Store a -> (a -> IO b) -> IO b withStore s f =   do v <- readStore s