Giter Club home page Giter Club logo

innertube's Introduction

Innertube

Innertube is a thread-safe, re-entrant resource pool, extracted from the Riak Ruby Client, where it was used to pool connections to Riak. It is free to use and modify, licensed under the Apache 2.0 License.

Example

# -------------------------------------------------------
# Basics
# -------------------------------------------------------

# Create a pool with open/close callables
pool = Innertube::Pool.new(proc { Connection.new },
                           proc {|c| c.disconnect })

# Optionally, fill the pool with existing resources
pool.fill([conn1, conn2, conn3])

# Grab a connection from the pool, returns the same value
# as the block
pool.take {|conn| conn.ping } # => true

# Raise the BadResource exception if the resource is no
# longer good
pool.take do |conn|
  raise Innertube::Pool::BadResource unless conn.connected?
  conn.ping
end

# Innertube helps your code be re-entrant! Take more resources
# while you have one checked out.
pool.take do |conn|
  conn.stream_tweets do |tweet|
    pool.take {|conn2| conn2.increment :tweets }
  end
end

# -------------------------------------------------------
# Iterations: These are slow because they have guarantees
# about visiting all current elements of the pool.
# -------------------------------------------------------

# Do something with every connection in the pool
pool.each {|conn| puts conn.get_stats }

# Expunge some expired connections from the pool
pool.delete_if {|conn| conn.idle_time > 5 }

Credits

The pool was originally implemented by Kyle Kingsbury and extracted by Sean Cribbs, when bugged about it by Pat Allan at EuRuKo 2012.

innertube's People

Contributors

ktdreyer avatar righi avatar seancribbs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.