add method to snapshot TBQueue without flushing
- Dominant language
- Haskell
- Stars
- 118
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Currently there is no way to efficiently snapshot the state of TBQueue without flushing it and rewriting (and neither there is a way to efficiently create TBQueue from the list). What is required to do to a snapshot now:
```haskell
snapshotTBQueue :: TBQueue a -> STM [a]
snapshotTBQueue q = do
xs <- flushTBQueue q
mapM_ (writeTBQueue q) xs
pure xs
```
But snapshot is a part of flushTBQueue, and if TBQueue constructor was exported it could have been implemented outside in this way:
```haskell
snapshotTBQueue :: TBQueue a -> STM [a]
snapshotTBQueue (TBQueue _ read _ write _) = do
xs <- readTVar read
ys <- readTVar write
return $ if null xs && null is then [] else xs ++ reverse ys
```
The use case for snapshot is dumping a state of the queue(s) to the hard-drive, so it can be efficiently snapshotted before dump starts (so that the state is consistent).
Could we add snapshot to STM? Alternatively, could we export TBQueue constructor?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.