Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module defines the WeakBag
type, which represents a mutable
collection of items that does not cause the items to be retained in memory.
This is useful for situations where a value needs to be inspected or modified
if it is still alive, but can be ignored if it is dead.
Synopsis
- data WeakBag a
- data WeakBagTicket
- empty :: IO (WeakBag a)
- singleton :: a -> IORef (Weak b) -> (b -> IO ()) -> IO (WeakBag a, WeakBagTicket)
- insert :: a -> WeakBag a -> IORef (Weak b) -> (b -> IO ()) -> IO WeakBagTicket
- traverse :: MonadIO m => WeakBag a -> (a -> m ()) -> m ()
- traverse_ :: MonadIO m => WeakBag a -> (a -> m ()) -> m ()
- remove :: WeakBagTicket -> IO ()
- _weakBag_children :: WeakBag a -> IORef (IntMap (Weak a))
Documentation
data WeakBagTicket Source #
When inserting an item into a WeakBag
, a WeakBagTicket
is returned. If
the caller retains the ticket, the item is guranteed to stay in memory (and
thus in the WeakBag
). The ticket can also be used to remove the item from
the WeakBag
prematurely (i.e. while it is still alive), using remove
.
:: a | The item |
-> WeakBag a | The |
-> IORef (Weak b) | An arbitrary value to be used in the following callback |
-> (b -> IO ()) | A callback to be invoked when the item is removed
(whether automatically by the item being garbage
collected or manually via |
-> IO WeakBagTicket | Returns a |
Insert an item into a WeakBag
.
traverse_ :: MonadIO m => WeakBag a -> (a -> m ()) -> m () Source #
Visit every node in the given list. If new nodes are appended during the traversal, they will not be visited. Every live node that was in the list when the traversal began will be visited exactly once; however, no guarantee is made about the order of the traversal.
remove :: WeakBagTicket -> IO () Source #
Remove an item from the WeakBag
; does nothing if invoked multiple times
on the same WeakBagTicket
.