Cycle through a set of resources (randomly), recreating them when they expire
- data Factory e r = Factory {
- newResource :: ErrorT e IO r
- killResource :: r -> IO ()
- isExpired :: r -> IO Bool
- newPool :: Factory e r -> Int -> IO (Pool e r)
- data Pool e r = Pool {}
- aResource :: Error e => Pool e r -> ErrorT e IO r
- poolSize :: Pool e r -> IO Int
- resize :: Pool e r -> Int -> IO ()
- killAll :: Pool e r -> IO ()
Documentation
Creator, destroyer, and checker of resources of type r. Creator may throw error or type e.
Factory | |
|
newPool :: Factory e r -> Int -> IO (Pool e r)Source
Create new pool of initial max size, which must be >= 1
Pool of maximum N resources. Resources may expire on their own or be killed. Resources will initially be created on demand up N resources then recycled in random fashion. N may be changed by resizing the pool. Random is preferred to round-robin to distribute effect of pathological use cases that use every Xth resource the most and N is a multiple of X.
Resources *must* close/kill themselves when garbage collected (resize
relies on this).
aResource :: Error e => Pool e r -> ErrorT e IO rSource
Return a random live resource in pool or create new one if expired or not yet created