Skip to content

Can we add timeout for resource acquiring? #10

@goosedb

Description

@goosedb

Can we add optional timeout for resource acquiring? Not for creating but taking resource. For now pool waits for available resource infinitely that can be a reason of dead locks.

main :: IO ()
main = do
  pool <- newPool PoolConfig 
    { createResource = pure 0
    , freeResource = const (pure ())
    , poolCacheTTL = 60
    , poolMaxResources = 3
    }

  let takeAnd action = withResource pool (const action)

  putStrLn "-------------\n 1st\n-------------"
  takeAnd do
    print 1
    takeAnd do
      print 2
      takeAnd do 
        print 3
        putStrLn "here!"

  putStrLn "-------------\n 2nd\n-------------"
  takeAnd do
    print 1
    takeAnd do
      print 2
      takeAnd do 
        print 3
        takeAnd do 
          print 4
          putStrLn "here!"

prints

-------------
 1st
-------------
1
2
3
here!
-------------
 2nd
-------------
1
2
3

And gets stuck. Of course, it's a user-code bug. But it's better to get exception than get stuck forever

I'm ready to implement it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions