simplepool

Simple thread-safe pool for anything that is not thread-safe
HEAD Latest release Yanked release released

Linux CI MacOS CI Windows CI API Documentation

simplepool

Simple thread-safe pool for anything that is not thread-safe.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      simplepool:
        github: konovod/simplepool
    
  2. Run shards install

Usage

require "simplepool"
# Note that `MyConnection.new` will be protected by mutex, so can be not thread-safe
pool = SimplePool(MyConnection).new { MyConnection.new(address, port) }
10.times do
  spawn do
    # get object from pool
    conn = pool.get
    work_with(conn)
    # don't forget to return it
    pool.return(conn)
  end
end
10.times do
  spawn do
    # safe version as you don't need to explicitely return it
    pool.use do |conn|
      work_with conn
      raise "error" # object will be returned to pool even after raise
    end
  end
end

Docs on API are available on https://konovod.github.io/simplepool

Contributing

  1. Fork it (https://github.com/konovod/simplepool/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

simplepool:
  github: konovod/simplepool
  
License MIT
Crystal 1.7.2

Authors

Dependencies 0

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently