restify 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +1 -1
  4. data/lib/restify/adapter/base.rb +1 -1
  5. data/lib/restify/cache.rb +1 -1
  6. data/lib/restify/relation.rb +7 -11
  7. data/lib/restify/response.rb +2 -2
  8. data/lib/restify/version.rb +2 -2
  9. data/spec/restify/adapter/base_spec.rb +33 -0
  10. data/spec/restify/context_spec.rb +2 -2
  11. data/spec/restify/features/opentelemetry_spec.rb +1 -1
  12. data/spec/restify/global_spec.rb +50 -1
  13. data/spec/restify/link_spec.rb +13 -3
  14. data/spec/restify/relation_spec.rb +79 -7
  15. data/spec/restify/resource_spec.rb +6 -0
  16. data/spec/restify_spec.rb +1 -1
  17. data/spec/spec_helper.rb +0 -1
  18. data/vendor/bundle/ruby/4.0.0/bundler/gems/my-rubocop-2b861962124a/LICENSE +21 -0
  19. data/vendor/bundle/ruby/4.0.0/bundler/gems/my-rubocop-2b861962124a/README.md +23 -0
  20. data/vendor/bundle/ruby/4.0.0/gems/activesupport-8.1.3/CHANGELOG.md +561 -0
  21. data/vendor/bundle/ruby/4.0.0/gems/activesupport-8.1.3/MIT-LICENSE +20 -0
  22. data/vendor/bundle/ruby/4.0.0/gems/activesupport-8.1.3/README.rdoc +40 -0
  23. data/vendor/bundle/ruby/4.0.0/gems/addressable-2.9.0/CHANGELOG.md +326 -0
  24. data/vendor/bundle/ruby/4.0.0/gems/addressable-2.9.0/LICENSE.txt +202 -0
  25. data/vendor/bundle/ruby/4.0.0/gems/addressable-2.9.0/README.md +121 -0
  26. data/vendor/bundle/ruby/4.0.0/gems/ast-2.4.3/LICENSE.MIT +20 -0
  27. data/vendor/bundle/ruby/4.0.0/gems/ast-2.4.3/README.YARD.md +12 -0
  28. data/vendor/bundle/ruby/4.0.0/gems/base64-0.3.0/README.md +48 -0
  29. data/vendor/bundle/ruby/4.0.0/gems/bigdecimal-4.1.2/LICENSE +56 -0
  30. data/vendor/bundle/ruby/4.0.0/gems/concurrent-ruby-1.3.7/CHANGELOG.md +615 -0
  31. data/vendor/bundle/ruby/4.0.0/gems/concurrent-ruby-1.3.7/LICENSE.txt +21 -0
  32. data/vendor/bundle/ruby/4.0.0/gems/concurrent-ruby-1.3.7/README.md +409 -0
  33. data/vendor/bundle/ruby/4.0.0/gems/connection_pool-3.0.2/LICENSE +20 -0
  34. data/vendor/bundle/ruby/4.0.0/gems/connection_pool-3.0.2/README.md +182 -0
  35. data/vendor/bundle/ruby/4.0.0/gems/crack-1.0.1/LICENSE +20 -0
  36. data/vendor/bundle/ruby/4.0.0/gems/crack-1.0.1/README.md +43 -0
  37. data/vendor/bundle/ruby/4.0.0/gems/diff-lcs-1.6.2/CHANGELOG.md +518 -0
  38. data/vendor/bundle/ruby/4.0.0/gems/diff-lcs-1.6.2/README.md +92 -0
  39. data/vendor/bundle/ruby/4.0.0/gems/docile-1.4.1/LICENSE +21 -0
  40. data/vendor/bundle/ruby/4.0.0/gems/docile-1.4.1/README.md +409 -0
  41. data/vendor/bundle/ruby/4.0.0/gems/drb-2.2.3/LICENSE.txt +22 -0
  42. data/vendor/bundle/ruby/4.0.0/gems/ethon-0.18.0/CHANGELOG.md +417 -0
  43. data/vendor/bundle/ruby/4.0.0/gems/ethon-0.18.0/LICENSE +20 -0
  44. data/vendor/bundle/ruby/4.0.0/gems/ethon-0.18.0/README.md +118 -0
  45. data/vendor/bundle/ruby/4.0.0/gems/ffi-1.17.4-x86_64-linux-gnu/CHANGELOG.md +507 -0
  46. data/vendor/bundle/ruby/4.0.0/gems/ffi-1.17.4-x86_64-linux-gnu/LICENSE +24 -0
  47. data/vendor/bundle/ruby/4.0.0/gems/ffi-1.17.4-x86_64-linux-gnu/LICENSE.SPECS +22 -0
  48. data/vendor/bundle/ruby/4.0.0/gems/ffi-1.17.4-x86_64-linux-gnu/README.md +138 -0
  49. data/vendor/bundle/ruby/4.0.0/gems/hashdiff-1.2.1/LICENSE +19 -0
  50. data/vendor/bundle/ruby/4.0.0/gems/hashdiff-1.2.1/README.md +323 -0
  51. data/vendor/bundle/ruby/4.0.0/gems/hashdiff-1.2.1/changelog.md +127 -0
  52. data/vendor/bundle/ruby/4.0.0/gems/hitimes-3.2.0/LICENSE.txt +16 -0
  53. data/vendor/bundle/ruby/4.0.0/gems/hitimes-3.2.0/README.md +187 -0
  54. data/vendor/bundle/ruby/4.0.0/gems/i18n-1.15.2/MIT-LICENSE +20 -0
  55. data/vendor/bundle/ruby/4.0.0/gems/i18n-1.15.2/README.md +139 -0
  56. data/vendor/bundle/ruby/4.0.0/gems/json-2.19.9/README.md +310 -0
  57. data/vendor/bundle/ruby/4.0.0/gems/language_server-protocol-3.17.0.5/LICENSE.txt +21 -0
  58. data/vendor/bundle/ruby/4.0.0/gems/language_server-protocol-3.17.0.5/README.md +88 -0
  59. data/vendor/bundle/ruby/4.0.0/gems/lint_roller-1.1.0/CHANGELOG.md +15 -0
  60. data/vendor/bundle/ruby/4.0.0/gems/lint_roller-1.1.0/LICENSE.txt +21 -0
  61. data/vendor/bundle/ruby/4.0.0/gems/lint_roller-1.1.0/README.md +173 -0
  62. data/vendor/bundle/ruby/4.0.0/gems/little-plugger-1.1.4/README.rdoc +53 -0
  63. data/vendor/bundle/ruby/4.0.0/gems/logger-1.7.0/README.md +104 -0
  64. data/vendor/bundle/ruby/4.0.0/gems/logging-2.4.0/LICENSE +22 -0
  65. data/vendor/bundle/ruby/4.0.0/gems/logging-2.4.0/README.md +140 -0
  66. data/vendor/bundle/ruby/4.0.0/gems/minitest-6.0.6/README.rdoc +763 -0
  67. data/vendor/bundle/ruby/4.0.0/gems/msgpack-1.8.3/ChangeLog +383 -0
  68. data/vendor/bundle/ruby/4.0.0/gems/msgpack-1.8.3/LICENSE +177 -0
  69. data/vendor/bundle/ruby/4.0.0/gems/msgpack-1.8.3/README.md +302 -0
  70. data/vendor/bundle/ruby/4.0.0/gems/multi_json-1.21.1/LICENSE.md +20 -0
  71. data/vendor/bundle/ruby/4.0.0/gems/multi_json-1.21.1/README.md +281 -0
  72. data/vendor/bundle/ruby/4.0.0/gems/nio4r-2.7.5/ext/libev/LICENSE +37 -0
  73. data/vendor/bundle/ruby/4.0.0/gems/nio4r-2.7.5/ext/libev/README +59 -0
  74. data/vendor/bundle/ruby/4.0.0/gems/nio4r-2.7.5/license.md +80 -0
  75. data/vendor/bundle/ruby/4.0.0/gems/nio4r-2.7.5/readme.md +91 -0
  76. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-api-1.10.0/CHANGELOG.md +219 -0
  77. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-api-1.10.0/LICENSE +201 -0
  78. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-api-1.10.0/README.md +68 -0
  79. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-common-0.25.0/CHANGELOG.md +110 -0
  80. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-common-0.25.0/LICENSE +201 -0
  81. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-common-0.25.0/README.md +62 -0
  82. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-base-0.26.1/CHANGELOG.md +97 -0
  83. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-base-0.26.1/LICENSE +201 -0
  84. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-base-0.26.1/README.md +155 -0
  85. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-ethon-0.29.0/CHANGELOG.md +192 -0
  86. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-ethon-0.29.0/LICENSE +201 -0
  87. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-instrumentation-ethon-0.29.0/README.md +66 -0
  88. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-registry-0.6.0/CHANGELOG.md +31 -0
  89. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-registry-0.6.0/LICENSE +201 -0
  90. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-registry-0.6.0/README.md +40 -0
  91. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-sdk-1.12.0/CHANGELOG.md +302 -0
  92. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-sdk-1.12.0/LICENSE +201 -0
  93. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-sdk-1.12.0/README.md +101 -0
  94. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-semantic_conventions-1.41.0/CHANGELOG.md +65 -0
  95. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-semantic_conventions-1.41.0/LICENSE +201 -0
  96. data/vendor/bundle/ruby/4.0.0/gems/opentelemetry-semantic_conventions-1.41.0/README.md +115 -0
  97. data/vendor/bundle/ruby/4.0.0/gems/parallel-2.1.0/MIT-LICENSE.txt +20 -0
  98. data/vendor/bundle/ruby/4.0.0/gems/parser-3.3.11.1/LICENSE.txt +26 -0
  99. data/vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/CHANGELOG.md +786 -0
  100. data/vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/LICENSE.md +7 -0
  101. data/vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/README.md +143 -0
  102. data/vendor/bundle/ruby/4.0.0/gems/public_suffix-7.0.5/CHANGELOG.md +649 -0
  103. data/vendor/bundle/ruby/4.0.0/gems/public_suffix-7.0.5/LICENSE.txt +22 -0
  104. data/vendor/bundle/ruby/4.0.0/gems/public_suffix-7.0.5/README.md +231 -0
  105. data/vendor/bundle/ruby/4.0.0/gems/puma-8.0.2/LICENSE +29 -0
  106. data/vendor/bundle/ruby/4.0.0/gems/puma-8.0.2/README.md +484 -0
  107. data/vendor/bundle/ruby/4.0.0/gems/puma-8.0.2/docs/jungle/README.md +9 -0
  108. data/vendor/bundle/ruby/4.0.0/gems/puma-8.0.2/docs/jungle/rc.d/README.md +74 -0
  109. data/vendor/bundle/ruby/4.0.0/gems/racc-1.8.1/ChangeLog +846 -0
  110. data/vendor/bundle/ruby/4.0.0/gems/racc-1.8.1/README.ja.rdoc +58 -0
  111. data/vendor/bundle/ruby/4.0.0/gems/racc-1.8.1/README.rdoc +60 -0
  112. data/vendor/bundle/ruby/4.0.0/gems/rack-3.2.6/CHANGELOG.md +1346 -0
  113. data/vendor/bundle/ruby/4.0.0/gems/rack-3.2.6/MIT-LICENSE +20 -0
  114. data/vendor/bundle/ruby/4.0.0/gems/rack-3.2.6/README.md +384 -0
  115. data/vendor/bundle/ruby/4.0.0/gems/rainbow-3.1.1/Changelog.md +101 -0
  116. data/vendor/bundle/ruby/4.0.0/gems/rainbow-3.1.1/LICENSE +20 -0
  117. data/vendor/bundle/ruby/4.0.0/gems/rainbow-3.1.1/README.markdown +227 -0
  118. data/vendor/bundle/ruby/4.0.0/gems/rake-13.4.2/MIT-LICENSE +21 -0
  119. data/vendor/bundle/ruby/4.0.0/gems/rake-13.4.2/README.rdoc +155 -0
  120. data/vendor/bundle/ruby/4.0.0/gems/rake-release-1.4.0/LICENSE +21 -0
  121. data/vendor/bundle/ruby/4.0.0/gems/rake-release-1.4.0/README.md +107 -0
  122. data/vendor/bundle/ruby/4.0.0/gems/regexp_parser-2.12.0/LICENSE +22 -0
  123. data/vendor/bundle/ruby/4.0.0/gems/rexml-3.4.4/LICENSE.txt +22 -0
  124. data/vendor/bundle/ruby/4.0.0/gems/rexml-3.4.4/README.md +57 -0
  125. data/vendor/bundle/ruby/4.0.0/gems/rspec-3.13.2/LICENSE.md +27 -0
  126. data/vendor/bundle/ruby/4.0.0/gems/rspec-3.13.2/README.md +47 -0
  127. data/vendor/bundle/ruby/4.0.0/gems/rspec-core-3.13.6/Changelog.md +2447 -0
  128. data/vendor/bundle/ruby/4.0.0/gems/rspec-core-3.13.6/LICENSE.md +26 -0
  129. data/vendor/bundle/ruby/4.0.0/gems/rspec-core-3.13.6/README.md +389 -0
  130. data/vendor/bundle/ruby/4.0.0/gems/rspec-expectations-3.13.5/Changelog.md +1366 -0
  131. data/vendor/bundle/ruby/4.0.0/gems/rspec-expectations-3.13.5/LICENSE.md +25 -0
  132. data/vendor/bundle/ruby/4.0.0/gems/rspec-expectations-3.13.5/README.md +326 -0
  133. data/vendor/bundle/ruby/4.0.0/gems/rspec-mocks-3.13.8/Changelog.md +1351 -0
  134. data/vendor/bundle/ruby/4.0.0/gems/rspec-mocks-3.13.8/LICENSE.md +25 -0
  135. data/vendor/bundle/ruby/4.0.0/gems/rspec-mocks-3.13.8/README.md +465 -0
  136. data/vendor/bundle/ruby/4.0.0/gems/rspec-support-3.13.7/Changelog.md +444 -0
  137. data/vendor/bundle/ruby/4.0.0/gems/rspec-support-3.13.7/LICENSE.md +23 -0
  138. data/vendor/bundle/ruby/4.0.0/gems/rspec-support-3.13.7/README.md +40 -0
  139. data/vendor/bundle/ruby/4.0.0/gems/rubocop-1.88.0/LICENSE.txt +20 -0
  140. data/vendor/bundle/ruby/4.0.0/gems/rubocop-1.88.0/README.md +255 -0
  141. data/vendor/bundle/ruby/4.0.0/gems/rubocop-ast-1.49.1/LICENSE.txt +20 -0
  142. data/vendor/bundle/ruby/4.0.0/gems/rubocop-ast-1.49.1/README.md +54 -0
  143. data/vendor/bundle/ruby/4.0.0/gems/rubocop-capybara-2.23.0/CHANGELOG.md +116 -0
  144. data/vendor/bundle/ruby/4.0.0/gems/rubocop-capybara-2.23.0/MIT-LICENSE.md +21 -0
  145. data/vendor/bundle/ruby/4.0.0/gems/rubocop-capybara-2.23.0/README.md +91 -0
  146. data/vendor/bundle/ruby/4.0.0/gems/rubocop-factory_bot-2.28.0/CHANGELOG.md +135 -0
  147. data/vendor/bundle/ruby/4.0.0/gems/rubocop-factory_bot-2.28.0/MIT-LICENSE.md +21 -0
  148. data/vendor/bundle/ruby/4.0.0/gems/rubocop-factory_bot-2.28.0/README.md +91 -0
  149. data/vendor/bundle/ruby/4.0.0/gems/rubocop-performance-1.26.1/LICENSE.txt +20 -0
  150. data/vendor/bundle/ruby/4.0.0/gems/rubocop-performance-1.26.1/README.md +100 -0
  151. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec-3.10.2/CHANGELOG.md +1136 -0
  152. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec-3.10.2/MIT-LICENSE.md +21 -0
  153. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec-3.10.2/README.md +112 -0
  154. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec_rails-2.32.0/CHANGELOG.md +98 -0
  155. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec_rails-2.32.0/MIT-LICENSE.md +21 -0
  156. data/vendor/bundle/ruby/4.0.0/gems/rubocop-rspec_rails-2.32.0/README.md +93 -0
  157. data/vendor/bundle/ruby/4.0.0/gems/ruby-progressbar-1.13.0/LICENSE.txt +19 -0
  158. data/vendor/bundle/ruby/4.0.0/gems/ruby-progressbar-1.13.0/README.md +131 -0
  159. data/vendor/bundle/ruby/4.0.0/gems/securerandom-0.4.1/README.md +72 -0
  160. data/vendor/bundle/ruby/4.0.0/gems/simplecov-0.22.0/CHANGELOG.md +191 -0
  161. data/vendor/bundle/ruby/4.0.0/gems/simplecov-0.22.0/LICENSE +20 -0
  162. data/vendor/bundle/ruby/4.0.0/gems/simplecov-0.22.0/README.md +974 -0
  163. data/vendor/bundle/ruby/4.0.0/gems/simplecov-cobertura-3.2.0/LICENSE +202 -0
  164. data/vendor/bundle/ruby/4.0.0/gems/simplecov-cobertura-3.2.0/README.md +65 -0
  165. data/vendor/bundle/ruby/4.0.0/gems/simplecov-html-0.13.2/CHANGELOG.md +114 -0
  166. data/vendor/bundle/ruby/4.0.0/gems/simplecov-html-0.13.2/LICENSE +20 -0
  167. data/vendor/bundle/ruby/4.0.0/gems/simplecov-html-0.13.2/README.md +30 -0
  168. data/vendor/bundle/ruby/4.0.0/gems/simplecov_json_formatter-0.1.4/CHANGELOG.md +13 -0
  169. data/vendor/bundle/ruby/4.0.0/gems/simplecov_json_formatter-0.1.4/README.md +29 -0
  170. data/vendor/bundle/ruby/4.0.0/gems/typhoeus-1.6.0/CHANGELOG.md +465 -0
  171. data/vendor/bundle/ruby/4.0.0/gems/typhoeus-1.6.0/LICENSE +22 -0
  172. data/vendor/bundle/ruby/4.0.0/gems/typhoeus-1.6.0/README.md +588 -0
  173. data/vendor/bundle/ruby/4.0.0/gems/tzinfo-2.0.6/LICENSE +19 -0
  174. data/vendor/bundle/ruby/4.0.0/gems/tzinfo-2.0.6/README.md +406 -0
  175. data/vendor/bundle/ruby/4.0.0/gems/unicode-display_width-3.2.0/CHANGELOG.md +299 -0
  176. data/vendor/bundle/ruby/4.0.0/gems/unicode-display_width-3.2.0/MIT-LICENSE.txt +22 -0
  177. data/vendor/bundle/ruby/4.0.0/gems/unicode-display_width-3.2.0/README.md +194 -0
  178. data/vendor/bundle/ruby/4.0.0/gems/unicode-emoji-4.2.0/CHANGELOG.md +202 -0
  179. data/vendor/bundle/ruby/4.0.0/gems/unicode-emoji-4.2.0/MIT-LICENSE.txt +20 -0
  180. data/vendor/bundle/ruby/4.0.0/gems/unicode-emoji-4.2.0/README.md +205 -0
  181. data/vendor/bundle/ruby/4.0.0/gems/uri-1.1.1/README.md +55 -0
  182. data/vendor/bundle/ruby/4.0.0/gems/webmock-3.26.2/CHANGELOG.md +2148 -0
  183. data/vendor/bundle/ruby/4.0.0/gems/webmock-3.26.2/LICENSE +20 -0
  184. data/vendor/bundle/ruby/4.0.0/gems/webmock-3.26.2/README.md +1229 -0
  185. metadata +171 -4
  186. data/doc/file.README.html +0 -192
@@ -0,0 +1,409 @@
1
+ # Concurrent Ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/concurrent-ruby.svg)](http://badge.fury.io/rb/concurrent-ruby)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
5
+ [![Gitter chat](https://img.shields.io/badge/IRC%20(gitter)-devs%20%26%20users-brightgreen.svg)](https://gitter.im/ruby-concurrency/concurrent-ruby)
6
+
7
+ Modern concurrency tools for Ruby. Inspired by
8
+ [Erlang](http://www.erlang.org/doc/reference_manual/processes.html),
9
+ [Clojure](http://clojure.org/concurrent_programming),
10
+ [Scala](http://akka.io/),
11
+ [Haskell](http://www.haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism#Concurrent_Haskell),
12
+ [F#](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx),
13
+ [C#](http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx),
14
+ [Java](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html),
15
+ and classic concurrency patterns.
16
+
17
+ <img src="https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/docs-source/logo/concurrent-ruby-logo-300x300.png" align="right" style="margin-left: 20px;" />
18
+
19
+ The design goals of this gem are:
20
+
21
+ * Be an 'unopinionated' toolbox that provides useful utilities without debating which is better
22
+ or why
23
+ * Remain free of external gem dependencies
24
+ * Stay true to the spirit of the languages providing inspiration
25
+ * But implement in a way that makes sense for Ruby
26
+ * Keep the semantics as idiomatic Ruby as possible
27
+ * Support features that make sense in Ruby
28
+ * Exclude features that don't make sense in Ruby
29
+ * Be small, lean, and loosely coupled
30
+ * Thread-safety
31
+ * Backward compatibility
32
+
33
+ ## Contributing
34
+
35
+ **This gem depends on
36
+ [contributions](https://github.com/ruby-concurrency/concurrent-ruby/graphs/contributors) and we
37
+ appreciate your help. Would you like to contribute? Great! Have a look at
38
+ [issues with `looking-for-contributor` label](https://github.com/ruby-concurrency/concurrent-ruby/issues?q=is%3Aissue+is%3Aopen+label%3Alooking-for-contributor).** And if you pick something up let us know on the issue.
39
+
40
+ You can also get started by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to concurrent-ruby on CodeTriage](https://www.codetriage.com/ruby-concurrency/concurrent-ruby). [![Open Source Helpers](https://www.codetriage.com/ruby-concurrency/concurrent-ruby/badges/users.svg)](https://www.codetriage.com/ruby-concurrency/concurrent-ruby)
41
+
42
+ ## Thread Safety
43
+
44
+ *Concurrent Ruby makes one of the strongest thread safety guarantees of any Ruby concurrency
45
+ library, providing consistent behavior and guarantees on all three main Ruby interpreters
46
+ (MRI/CRuby, JRuby, TruffleRuby).*
47
+
48
+ Every abstraction in this library is thread safe. Specific thread safety guarantees are documented
49
+ with each abstraction.
50
+
51
+ It is critical to remember, however, that Ruby is a language of mutable references. *No*
52
+ concurrency library for Ruby can ever prevent the user from making thread safety mistakes (such as
53
+ sharing a mutable object between threads and modifying it on both threads) or from creating
54
+ deadlocks through incorrect use of locks. All the library can do is provide safe abstractions which
55
+ encourage safe practices. Concurrent Ruby provides more safe concurrency abstractions than any
56
+ other Ruby library, many of which support the mantra of
57
+ ["Do not communicate by sharing memory; instead, share memory by communicating"](https://blog.golang.org/share-memory-by-communicating).
58
+ Concurrent Ruby is also the only Ruby library which provides a full suite of thread safe and
59
+ immutable variable types and data structures.
60
+
61
+ We've also initiated discussion to document the [memory model](docs-source/synchronization.md) of Ruby which
62
+ would provide consistent behaviour and guarantees on all three main Ruby interpreters
63
+ (MRI/CRuby, JRuby, TruffleRuby).
64
+
65
+ ## Features & Documentation
66
+
67
+ **The primary site for documentation is the automatically generated
68
+ [API documentation](http://ruby-concurrency.github.io/concurrent-ruby/index.html) which is up to
69
+ date with latest release.** This readme matches the master so may contain new stuff not yet
70
+ released.
71
+
72
+ We also have a [IRC (gitter)](https://gitter.im/ruby-concurrency/concurrent-ruby).
73
+
74
+ ### Versioning
75
+
76
+ * `concurrent-ruby` uses [Semantic Versioning](http://semver.org/)
77
+ * `concurrent-ruby-ext` has always same version as `concurrent-ruby`
78
+ * `concurrent-ruby-edge` will always be 0.y.z therefore following
79
+ [point 4](http://semver.org/#spec-item-4) applies *"Major version zero
80
+ (0.y.z) is for initial development. Anything may change at any time. The
81
+ public API should not be considered stable."* However we additionally use
82
+ following rules:
83
+ * Minor version increment means incompatible changes were made
84
+ * Patch version increment means only compatible changes were made
85
+
86
+
87
+ #### General-purpose Concurrency Abstractions
88
+
89
+ * [Async](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html):
90
+ A mixin module that provides simple asynchronous behavior to a class. Loosely based on Erlang's
91
+ [gen_server](http://www.erlang.org/doc/man/gen_server.html).
92
+ * [ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ScheduledTask.html):
93
+ Like a Future scheduled for a specific future time.
94
+ * [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TimerTask.html):
95
+ A Thread that periodically wakes up to perform work at regular intervals.
96
+ * [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html):
97
+ Unified implementation of futures and promises which combines features of previous `Future`,
98
+ `Promise`, `IVar`, `Event`, `dataflow`, `Delay`, and (partially) `TimerTask` into a single
99
+ framework. It extensively uses the new synchronization layer to make all the features
100
+ **non-blocking** and **lock-free**, with the exception of obviously blocking operations like
101
+ `#wait`, `#value`. It also offers better performance.
102
+
103
+ #### Thread-safe Value Objects, Structures, and Collections
104
+
105
+ Collection classes that were originally part of the (deprecated) `thread_safe` gem:
106
+
107
+ * [Array](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Array.html) A thread-safe
108
+ subclass of Ruby's standard [Array](http://ruby-doc.org/core/Array.html).
109
+ * [Hash](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Hash.html) A thread-safe
110
+ subclass of Ruby's standard [Hash](http://ruby-doc.org/core/Hash.html).
111
+ * [Set](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Set.html) A thread-safe
112
+ subclass of Ruby's standard [Set](http://ruby-doc.org/stdlib-2.4.0/libdoc/set/rdoc/Set.html).
113
+ * [Map](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Map.html) A hash-like object
114
+ that should have much better performance characteristics, especially under high concurrency,
115
+ than `Concurrent::Hash`.
116
+ * [Tuple](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Tuple.html) A fixed size
117
+ array with volatile (synchronized, thread safe) getters/setters.
118
+
119
+ Value objects inspired by other languages:
120
+
121
+ * [Maybe](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Maybe.html) A thread-safe,
122
+ immutable object representing an optional value, based on
123
+ [Haskell Data.Maybe](https://hackage.haskell.org/package/base-4.2.0.1/docs/Data-Maybe.html).
124
+
125
+ Structure classes derived from Ruby's [Struct](http://ruby-doc.org/core/Struct.html):
126
+
127
+ * [ImmutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ImmutableStruct.html)
128
+ Immutable struct where values are set at construction and cannot be changed later.
129
+ * [MutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MutableStruct.html)
130
+ Synchronized, mutable struct where values can be safely changed at any time.
131
+ * [SettableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/SettableStruct.html)
132
+ Synchronized, write-once struct where values can be set at most once, either at construction
133
+ or any time thereafter.
134
+
135
+ Thread-safe variables:
136
+
137
+ * [Agent](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Agent.html): A way to
138
+ manage shared, mutable, *asynchronous*, independent state. Based on Clojure's
139
+ [Agent](http://clojure.org/agents).
140
+ * [Atom](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Atom.html): A way to manage
141
+ shared, mutable, *synchronous*, independent state. Based on Clojure's
142
+ [Atom](http://clojure.org/atoms).
143
+ * [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicBoolean.html)
144
+ A boolean value that can be updated atomically.
145
+ * [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicFixnum.html)
146
+ A numeric value that can be updated atomically.
147
+ * [AtomicReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicReference.html)
148
+ An object reference that may be updated atomically.
149
+ * [Exchanger](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Exchanger.html)
150
+ A synchronization point at which threads can pair and swap elements within pairs. Based on
151
+ Java's [Exchanger](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Exchanger.html).
152
+ * [MVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MVar.html) A synchronized
153
+ single element container. Based on Haskell's
154
+ [MVar](https://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Concurrent-MVar.html) and
155
+ Scala's [MVar](http://docs.typelevel.org/api/scalaz/nightly/index.html#scalaz.concurrent.MVar$).
156
+ * [ThreadLocalVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ThreadLocalVar.html)
157
+ A variable where the value is different for each thread.
158
+ * [TVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TVar.html) A transactional
159
+ variable implementing software transactional memory (STM). Based on Clojure's
160
+ [Ref](http://clojure.org/refs).
161
+
162
+ #### Java-inspired ThreadPools and Other Executors
163
+
164
+ * See the [thread pool](http://ruby-concurrency.github.io/concurrent-ruby/master/file.thread_pools.html)
165
+ overview, which also contains a list of other Executors available.
166
+
167
+ #### Thread Synchronization Classes and Algorithms
168
+
169
+ * [CountDownLatch](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CountDownLatch.html)
170
+ A synchronization object that allows one thread to wait on multiple other threads.
171
+ * [CyclicBarrier](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CyclicBarrier.html)
172
+ A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.
173
+ * [Event](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Event.html) Old school
174
+ kernel-style event.
175
+ * [ReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReadWriteLock.html)
176
+ A lock that supports multiple readers but only one writer.
177
+ * [ReentrantReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReentrantReadWriteLock.html)
178
+ A read/write lock with reentrant and upgrade features.
179
+ * [Semaphore](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Semaphore.html)
180
+ A counting-based locking mechanism that uses permits.
181
+ * [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicMarkableReference.html)
182
+
183
+ #### Deprecated
184
+
185
+ Deprecated features are still available and bugs are being fixed, but new features will not be added.
186
+
187
+ * ~~[Future](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Future.html):
188
+ An asynchronous operation that produces a value.~~ Replaced by
189
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
190
+ * ~~[.dataflow](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#dataflow-class_method):
191
+ Built on Futures, Dataflow allows you to create a task that will be scheduled when all of
192
+ its data dependencies are available.~~ Replaced by
193
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
194
+ * ~~[Promise](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promise.html): Similar
195
+ to Futures, with more features.~~ Replaced by
196
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
197
+ * ~~[Delay](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Delay.html) Lazy evaluation
198
+ of a block yielding an immutable result. Based on Clojure's
199
+ [delay](https://clojuredocs.org/clojure.core/delay).~~ Replaced by
200
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
201
+ * ~~[IVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/IVar.html) Similar to a
202
+ "future" but can be manually assigned once, after which it becomes immutable.~~ Replaced by
203
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
204
+
205
+ ### Edge Features
206
+
207
+ These are available in the `concurrent-ruby-edge` companion gem.
208
+
209
+ These features are under active development and may change frequently. They are expected not to
210
+ keep backward compatibility (they may also lack tests and documentation). Semantic versions will
211
+ be obeyed though. Features developed in `concurrent-ruby-edge` are expected to move to
212
+ `concurrent-ruby` when final.
213
+
214
+ * [Actor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Actor.html): Implements
215
+ the Actor Model, where concurrent actors exchange messages.
216
+ *Status: Partial documentation and tests; depends on new future/promise framework; stability is good.*
217
+ * [Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Channel.html):
218
+ Communicating Sequential Processes ([CSP](https://en.wikipedia.org/wiki/Communicating_sequential_processes)).
219
+ Functionally equivalent to Go [channels](https://tour.golang.org/concurrency/2) with additional
220
+ inspiration from Clojure [core.async](https://clojure.github.io/core.async/).
221
+ *Status: Partial documentation and tests.*
222
+ * [LazyRegister](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LazyRegister.html)
223
+ * [LockFreeLinkedSet](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Edge/LockFreeLinkedSet.html)
224
+ *Status: will be moved to core soon.*
225
+ * [LockFreeStack](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LockFreeStack.html)
226
+ *Status: missing documentation and tests.*
227
+ * [Promises::Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises/Channel.html)
228
+ A first in first out channel that accepts messages with push family of methods and returns
229
+ messages with pop family of methods.
230
+ Pop and push operations can be represented as futures, see `#pop_op` and `#push_op`.
231
+ The capacity of the channel can be limited to support back pressure, use capacity option in `#initialize`.
232
+ `#pop` method blocks ans `#pop_op` returns pending future if there is no message in the channel.
233
+ If the capacity is limited the `#push` method blocks and `#push_op` returns pending future.
234
+ * [Cancellation](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Cancellation.html)
235
+ The Cancellation abstraction provides cooperative cancellation.
236
+
237
+ The standard methods `Thread#raise` of `Thread#kill` available in Ruby
238
+ are very dangerous (see linked the blog posts bellow).
239
+ Therefore concurrent-ruby provides an alternative.
240
+
241
+ * <https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/>
242
+ * <http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/>
243
+ * <http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html>
244
+
245
+ It provides an object which represents a task which can be executed,
246
+ the task has to get the reference to the object and periodically cooperatively check that it is not cancelled.
247
+ Good practices to make tasks cancellable:
248
+ * check cancellation every cycle of a loop which does significant work,
249
+ * do all blocking actions in a loop with a timeout then on timeout check cancellation
250
+ and if ok block again with the timeout
251
+ * [Throttle](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Throttle.html)
252
+ A tool managing concurrency level of tasks.
253
+ * [ErlangActor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ErlangActor.html)
254
+ Actor implementation which precisely matches Erlang actor behaviour.
255
+ Requires at least Ruby 2.1 otherwise it's not loaded.
256
+ * [WrappingExecutor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/WrappingExecutor.html)
257
+ A delegating executor which modifies each task before the task is given to
258
+ the target executor it delegates to.
259
+
260
+ ## Supported Ruby versions
261
+
262
+ * MRI 2.3 and above
263
+ * Latest JRuby 9000
264
+ * Latest TruffleRuby
265
+
266
+ ## Usage
267
+
268
+ Everything within this gem can be loaded simply by requiring it:
269
+
270
+ ```ruby
271
+ require 'concurrent'
272
+ ```
273
+
274
+ You can also require a specific abstraction [part of the public documentation](https://ruby-concurrency.github.io/concurrent-ruby/master/index.html) since concurrent-ruby 1.2.0, for example:
275
+ ```ruby
276
+ require 'concurrent/map'
277
+ require 'concurrent/atomic/atomic_reference'
278
+ require 'concurrent/executor/fixed_thread_pool'
279
+ ```
280
+
281
+ To use the tools in the Edge gem it must be required separately:
282
+
283
+ ```ruby
284
+ require 'concurrent-edge'
285
+ ```
286
+
287
+ If the library does not behave as expected, `Concurrent.use_simple_logger(:DEBUG)` could
288
+ help to reveal the problem.
289
+
290
+ ## Installation
291
+
292
+ ```shell
293
+ gem install concurrent-ruby
294
+ ```
295
+
296
+ or add the following line to Gemfile:
297
+
298
+ ```ruby
299
+ gem 'concurrent-ruby', require: 'concurrent'
300
+ ```
301
+
302
+ and run `bundle install` from your shell.
303
+
304
+ ### Edge Gem Installation
305
+
306
+ The Edge gem must be installed separately from the core gem:
307
+
308
+ ```shell
309
+ gem install concurrent-ruby-edge
310
+ ```
311
+
312
+ or add the following line to Gemfile:
313
+
314
+ ```ruby
315
+ gem 'concurrent-ruby-edge', require: 'concurrent-edge'
316
+ ```
317
+
318
+ and run `bundle install` from your shell.
319
+
320
+
321
+ ### C Extensions for MRI
322
+
323
+ Potential performance improvements may be achieved under MRI by installing optional C extensions.
324
+ To minimise installation errors the C extensions are available in the `concurrent-ruby-ext`
325
+ extension gem. `concurrent-ruby` and `concurrent-ruby-ext` are always released together with same
326
+ version. Simply install the extension gem too:
327
+
328
+ ```ruby
329
+ gem install concurrent-ruby-ext
330
+ ```
331
+
332
+ or add the following line to Gemfile:
333
+
334
+ ```ruby
335
+ gem 'concurrent-ruby-ext'
336
+ ```
337
+
338
+ and run `bundle install` from your shell.
339
+
340
+ In code it is only necessary to
341
+
342
+ ```ruby
343
+ require 'concurrent'
344
+ ```
345
+
346
+ The `concurrent-ruby` gem will automatically detect the presence of the `concurrent-ruby-ext` gem
347
+ and load the appropriate C extensions.
348
+
349
+ #### Note For gem developers
350
+
351
+ No gems should depend on `concurrent-ruby-ext`. Doing so will force C extensions on your users. The
352
+ best practice is to depend on `concurrent-ruby` and let users to decide if they want C extensions.
353
+
354
+ ## Building the gem
355
+
356
+ ### Requirements
357
+
358
+ * Recent CRuby
359
+ * JRuby, `rbenv install jruby-9.2.17.0`
360
+ * Set env variable `CONCURRENT_JRUBY_HOME` to point to it, e.g. `/usr/local/opt/rbenv/versions/jruby-9.2.17.0`
361
+ * Install Docker or Podman, required for Windows builds
362
+ * If `bundle config get path` is set, use `bundle config set --local path.system true` otherwise the `gem name, path: '.'` gems won't be found (Bundler limitation).
363
+
364
+ ### Publishing the Gem
365
+
366
+ * Update `version.rb`
367
+ * Update the CHANGELOG
368
+ * Add the new version to `docs-source/signpost.md`. Needs to be done only if there are visible changes in the documentation.
369
+ * Commit (and push) the changes.
370
+ * Use `bundle exec rake release` to release the gem.
371
+ It consists of `['release:checks', 'release:build', 'release:test', 'release:publish']` steps.
372
+ It will ask at the end before publishing anything. Steps can also be executed individually.
373
+
374
+ ## Maintainers
375
+
376
+ * [Benoit Daloze](https://github.com/eregon)
377
+ * [Matthew Draper](https://github.com/matthewd)
378
+ * [Rafael França](https://github.com/rafaelfranca)
379
+ * [Charles Oliver Nutter](https://github.com/headius)
380
+ * [Ben Sheldon](https://github.com/bensheldon)
381
+ * [Samuel Williams](https://github.com/ioquatix)
382
+ * [Joshua Young](https://github.com/joshuay03)
383
+
384
+ ### Special Thanks to
385
+
386
+ * [Jerry D'Antonio](https://github.com/jdantonio) for creating the gem
387
+ * [Brian Durand](https://github.com/bdurand) for the `ref` gem
388
+ * [Charles Oliver Nutter](https://github.com/headius) for the `atomic` and `thread_safe` gems
389
+ * [thedarkone](https://github.com/thedarkone) for the `thread_safe` gem
390
+
391
+ to the past maintainers
392
+
393
+ * [Chris Seaton](https://github.com/chrisseaton)
394
+ * [Petr Chalupa](https://github.com/pitr-ch)
395
+ * [Michele Della Torre](https://github.com/mighe)
396
+ * [Paweł Obrok](https://github.com/obrok)
397
+ * [Lucas Allan](https://github.com/lucasallan)
398
+
399
+ and to [Ruby Association](https://www.ruby.or.jp/en/) for sponsoring a project
400
+ ["Enhancing Ruby’s concurrency tooling"](https://www.ruby.or.jp/en/news/20181106) in 2018.
401
+
402
+ ## License and Copyright
403
+
404
+ *Concurrent Ruby* is free software released under the
405
+ [MIT License](http://www.opensource.org/licenses/MIT).
406
+
407
+ The *Concurrent Ruby* [logo](https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/docs-source/logo/concurrent-ruby-logo-300x300.png) was
408
+ designed by [David Jones](https://twitter.com/zombyboy). It is Copyright &copy; 2014
409
+ [Jerry D'Antonio](https://twitter.com/jerrydantonio). All Rights Reserved.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Mike Perham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,182 @@
1
+ connection\_pool
2
+ =================
3
+ [![Build Status](https://github.com/mperham/connection_pool/actions/workflows/ci.yml/badge.svg)](https://github.com/mperham/connection_pool/actions/workflows/ci.yml)
4
+
5
+ Generic connection pooling for Ruby.
6
+
7
+ MongoDB has its own connection pool.
8
+ ActiveRecord has its own connection pool.
9
+ This is a generic connection pool that can be used with anything, e.g. Redis, Dalli and other Ruby network clients.
10
+
11
+ Usage
12
+ -----
13
+
14
+ Create a pool of objects to share amongst the fibers or threads in your Ruby application:
15
+
16
+ ``` ruby
17
+ $memcached = ConnectionPool.new(size: 5, timeout: 5) { Dalli::Client.new }
18
+ ```
19
+
20
+ Then use the pool in your application:
21
+
22
+ ``` ruby
23
+ $memcached.with do |conn|
24
+ conn.get('some-count')
25
+ end
26
+ ```
27
+
28
+ If all the objects in the connection pool are in use, `with` will block
29
+ until one becomes available.
30
+ If no object is available within `:timeout` seconds,
31
+ `with` will raise a `ConnectionPool::TimeoutError` (a subclass of `Timeout::Error`).
32
+
33
+ You can also use `ConnectionPool#then` to support _both_ a
34
+ connection pool and a raw client.
35
+
36
+ ```ruby
37
+ # Compatible with a raw Redis::Client, and ConnectionPool Redis
38
+ $redis.then { |r| r.set 'foo' 'bar' }
39
+ ```
40
+
41
+ Optionally, you can specify a timeout override:
42
+
43
+ ``` ruby
44
+ $memcached.with(timeout: 2.0) do |conn|
45
+ conn.get('some-count')
46
+ end
47
+ ```
48
+
49
+ This will only modify the timeout for this particular invocation.
50
+ This is useful if you want to fail-fast on certain non-critical
51
+ sections when a resource is not available, or conversely if you are comfortable blocking longer on a particular resource.
52
+
53
+ ## Migrating to a Connection Pool
54
+
55
+ You can use `ConnectionPool::Wrapper` to wrap a single global connection, making it easier to migrate existing connection code over time:
56
+
57
+ ``` ruby
58
+ $redis = ConnectionPool::Wrapper.new(size: 5, timeout: 3) { Redis.new }
59
+ $redis.sadd('foo', 1)
60
+ $redis.smembers('foo')
61
+ ```
62
+
63
+ The wrapper uses `method_missing` to checkout a connection, run the requested method and then immediately check the connection back into the pool.
64
+ It's **not** high-performance so you'll want to port your performance sensitive code to use `with` as soon as possible.
65
+
66
+ ``` ruby
67
+ $redis.with do |conn|
68
+ conn.sadd('foo', 1)
69
+ conn.smembers('foo')
70
+ end
71
+ ```
72
+
73
+ Once you've ported your entire system to use `with`, you can remove `::Wrapper` and use `ConnectionPool` directly.
74
+
75
+
76
+ ## Shutdown
77
+
78
+ You can shut down a ConnectionPool instance once it should no longer be used.
79
+ Further checkout attempts will immediately raise an error but existing checkouts will work.
80
+
81
+ ```ruby
82
+ cp = ConnectionPool.new { Redis.new }
83
+ cp.shutdown { |c| c.close }
84
+ ```
85
+
86
+ Shutting down a connection pool will block until all connections are checked in and closed.
87
+ **Note that shutting down is completely optional**; Ruby's garbage collector will reclaim unreferenced pools under normal circumstances.
88
+
89
+ ## Reload
90
+
91
+ You can reload a ConnectionPool instance if it is necessary to close all existing connections and continue to use the pool.
92
+ ConnectionPool will automatically reload if the process is forked.
93
+ Use `auto_reload_after_fork: false` if you don't want this behavior.
94
+
95
+ ```ruby
96
+ cp = ConnectionPool.new(auto_reload_after_fork: false) { Redis.new }
97
+ cp.reload { |conn| conn.quit } # reload manually
98
+ cp.with { |conn| conn.get('some-count') }
99
+ ```
100
+
101
+ Like `shutdown`, `reload` will block until all connections are checked in and closed.
102
+
103
+ ## Reap
104
+
105
+ You can call `reap` periodically on the ConnectionPool instance to close connections that were created but have not been used for a certain amount of time. This can be useful in environments where connections are expensive.
106
+
107
+ You can specify how many seconds the connections have to be idle for them to be reaped, defaulting to 60 seconds.
108
+
109
+ ```ruby
110
+ cp = ConnectionPool.new { Redis.new }
111
+
112
+ # Start a reaper thread to reap connections that have been
113
+ # idle more than 300 seconds (5 minutes)
114
+ Thread.new do
115
+ loop do
116
+ cp.reap(idle_seconds: 300, &:close)
117
+ sleep 30
118
+ end
119
+ end
120
+ ```
121
+
122
+ ## Discarding Connections
123
+
124
+ You can discard connections in the ConnectionPool instance to remove connections that are broken and can't be repaired.
125
+ It can only be done inside the block passed to `with`.
126
+ Takes an optional block that will be executed with the connection.
127
+
128
+ ```ruby
129
+ pool.with do |conn|
130
+ begin
131
+ conn.execute("SELECT 1")
132
+ rescue SomeConnectionError
133
+ pool.discard_current_connection(&:close) # remove the connection from the pool
134
+ raise
135
+ end
136
+ end
137
+ ```
138
+
139
+ ## Current State
140
+
141
+ There are several methods that return information about a pool.
142
+
143
+ ```ruby
144
+ cp = ConnectionPool.new(size: 10) { Redis.new }
145
+ cp.size # => 10
146
+ cp.available # => 10
147
+ cp.idle # => 0
148
+
149
+ cp.with do |conn|
150
+ cp.size # => 10
151
+ cp.available # => 9
152
+ cp.idle # => 0
153
+ end
154
+
155
+ cp.idle # => 1
156
+ ```
157
+
158
+ ## Upgrading from ConnectionPool 2
159
+
160
+ * Support for Ruby <3.2 has been removed.
161
+ * ConnectionPool's APIs now consistently use keyword arguments everywhere.
162
+ Positional arguments must be converted to keywords:
163
+ ```ruby
164
+ pool = ConnectionPool.new(size: 5, timeout: 5)
165
+ pool.checkout(1) # 2.x
166
+ pool.reap(30) # 2.x
167
+ pool.checkout(timeout: 1) # 3.x
168
+ pool.reap(idle_seconds: 30) # 3.x
169
+ ```
170
+
171
+ ## Notes
172
+
173
+ - Connections are lazily created as needed.
174
+ - **WARNING**: Avoid `Timeout.timeout` in your Ruby code or you can see
175
+ occasional silent corruption and mysterious errors. The Timeout API is unsafe
176
+ and dangerous to use. Use proper socket timeout options as exposed by
177
+ Net::HTTP, Redis, Dalli, etc.
178
+
179
+
180
+ ## Author
181
+
182
+ Mike Perham, [@getajobmike](https://ruby.social/@getajobmike), <https://www.mikeperham.com>
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # crack
2
+
3
+ [![Test](https://github.com/jnunemaker/crack/actions/workflows/test.yml/badge.svg)](https://github.com/jnunemaker/crack/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/crack.svg)](https://badge.fury.io/rb/crack)
5
+ ![downloads](https://img.shields.io/gem/dt/crack?label=downloads)
6
+
7
+ Really simple JSON and XML parsing, ripped from Merb and Rails. The XML parser is ripped from Merb and the JSON parser is ripped from Rails. I take no credit, just packaged them for all to enjoy and easily use.
8
+
9
+ ## compatibility
10
+
11
+ * Ruby 2.x
12
+ * Ruby 3.x
13
+
14
+ ## note on patches/pull requests
15
+
16
+ * Fork the project.
17
+ * Make your feature addition or bug fix.
18
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
19
+ * Run the tests with `rake test`
20
+ * Open a Pull Request with the changes
21
+
22
+ ## usage
23
+
24
+ ```ruby
25
+ gem 'crack' # in Gemfile
26
+ require 'crack' # for xml and json
27
+ require 'crack/json' # for just json
28
+ require 'crack/xml' # for just xml
29
+ ```
30
+
31
+ ## examples
32
+
33
+ ```ruby
34
+ Crack::XML.parse("<tag>This is the contents</tag>")
35
+ # => {'tag' => 'This is the contents'}
36
+
37
+ Crack::JSON.parse('{"tag":"This is the contents"}')
38
+ # => {'tag' => 'This is the contents'}
39
+ ```
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2009 John Nunemaker. See LICENSE for details.