rbs 4.1.0.pre.2-java

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 (574) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.github/dependabot.yml +24 -0
  5. data/.github/workflows/bundle-update.yml +63 -0
  6. data/.github/workflows/c-check.yml +61 -0
  7. data/.github/workflows/comments.yml +37 -0
  8. data/.github/workflows/dependabot.yml +30 -0
  9. data/.github/workflows/jruby.yml +67 -0
  10. data/.github/workflows/milestone.yml +83 -0
  11. data/.github/workflows/ruby.yml +158 -0
  12. data/.github/workflows/rust.yml +184 -0
  13. data/.github/workflows/truffleruby.yml +54 -0
  14. data/.github/workflows/typecheck.yml +39 -0
  15. data/.github/workflows/wasm.yml +53 -0
  16. data/.github/workflows/windows.yml +49 -0
  17. data/.gitignore +38 -0
  18. data/.rubocop.yml +72 -0
  19. data/BSDL +22 -0
  20. data/CHANGELOG.md +2292 -0
  21. data/COPYING +56 -0
  22. data/README.md +240 -0
  23. data/Rakefile +869 -0
  24. data/Steepfile +53 -0
  25. data/config.yml +913 -0
  26. data/core/array.rbs +4142 -0
  27. data/core/basic_object.rbs +376 -0
  28. data/core/binding.rbs +148 -0
  29. data/core/builtin.rbs +278 -0
  30. data/core/class.rbs +223 -0
  31. data/core/comparable.rbs +192 -0
  32. data/core/complex.rbs +812 -0
  33. data/core/constants.rbs +96 -0
  34. data/core/data.rbs +415 -0
  35. data/core/dir.rbs +993 -0
  36. data/core/encoding.rbs +1368 -0
  37. data/core/enumerable.rbs +2506 -0
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +92 -0
  40. data/core/enumerator.rbs +705 -0
  41. data/core/env.rbs +6 -0
  42. data/core/errno.rbs +682 -0
  43. data/core/errors.rbs +789 -0
  44. data/core/exception.rbs +485 -0
  45. data/core/false_class.rbs +82 -0
  46. data/core/fiber.rbs +570 -0
  47. data/core/fiber_error.rbs +11 -0
  48. data/core/file.rbs +2045 -0
  49. data/core/file_constants.rbs +463 -0
  50. data/core/file_stat.rbs +534 -0
  51. data/core/file_test.rbs +331 -0
  52. data/core/float.rbs +1316 -0
  53. data/core/gc.rbs +788 -0
  54. data/core/global_variables.rbs +184 -0
  55. data/core/hash.rbs +2183 -0
  56. data/core/integer.rbs +1374 -0
  57. data/core/io/buffer.rbs +995 -0
  58. data/core/io/wait.rbs +48 -0
  59. data/core/io.rbs +3472 -0
  60. data/core/kernel.rbs +3172 -0
  61. data/core/marshal.rbs +207 -0
  62. data/core/match_data.rbs +637 -0
  63. data/core/math.rbs +770 -0
  64. data/core/method.rbs +422 -0
  65. data/core/module.rbs +1856 -0
  66. data/core/nil_class.rbs +210 -0
  67. data/core/numeric.rbs +832 -0
  68. data/core/object.rbs +108 -0
  69. data/core/object_space/weak_key_map.rbs +166 -0
  70. data/core/object_space.rbs +197 -0
  71. data/core/pathname.rbs +1322 -0
  72. data/core/proc.rbs +905 -0
  73. data/core/process.rbs +2316 -0
  74. data/core/ractor.rbs +924 -0
  75. data/core/random.rbs +255 -0
  76. data/core/range.rbs +1209 -0
  77. data/core/rational.rbs +502 -0
  78. data/core/rb_config.rbs +88 -0
  79. data/core/rbs/ops.rbs +154 -0
  80. data/core/rbs/unnamed/argf.rbs +1236 -0
  81. data/core/rbs/unnamed/env_class.rbs +1214 -0
  82. data/core/rbs/unnamed/main_class.rbs +123 -0
  83. data/core/rbs/unnamed/random.rbs +186 -0
  84. data/core/refinement.rbs +59 -0
  85. data/core/regexp.rbs +1974 -0
  86. data/core/ruby.rbs +53 -0
  87. data/core/ruby_vm.rbs +809 -0
  88. data/core/rubygems/basic_specification.rbs +6 -0
  89. data/core/rubygems/config_file.rbs +38 -0
  90. data/core/rubygems/dependency_installer.rbs +6 -0
  91. data/core/rubygems/errors.rbs +109 -0
  92. data/core/rubygems/installer.rbs +15 -0
  93. data/core/rubygems/path_support.rbs +6 -0
  94. data/core/rubygems/platform.rbs +7 -0
  95. data/core/rubygems/request_set.rbs +49 -0
  96. data/core/rubygems/requirement.rbs +148 -0
  97. data/core/rubygems/rubygems.rbs +1105 -0
  98. data/core/rubygems/source_list.rbs +15 -0
  99. data/core/rubygems/specification.rbs +23 -0
  100. data/core/rubygems/stream_ui.rbs +5 -0
  101. data/core/rubygems/uninstaller.rbs +10 -0
  102. data/core/rubygems/version.rbs +293 -0
  103. data/core/set.rbs +751 -0
  104. data/core/signal.rbs +110 -0
  105. data/core/string.rbs +5532 -0
  106. data/core/struct.rbs +668 -0
  107. data/core/symbol.rbs +482 -0
  108. data/core/thread.rbs +1826 -0
  109. data/core/thread_group.rbs +79 -0
  110. data/core/time.rbs +1793 -0
  111. data/core/trace_point.rbs +483 -0
  112. data/core/true_class.rbs +98 -0
  113. data/core/unbound_method.rbs +337 -0
  114. data/core/warning.rbs +87 -0
  115. data/docs/CONTRIBUTING.md +107 -0
  116. data/docs/aliases.md +79 -0
  117. data/docs/architecture.md +110 -0
  118. data/docs/collection.md +192 -0
  119. data/docs/config.md +171 -0
  120. data/docs/data_and_struct.md +86 -0
  121. data/docs/encoding.md +56 -0
  122. data/docs/gem.md +56 -0
  123. data/docs/inline.md +634 -0
  124. data/docs/rbs_by_example.md +309 -0
  125. data/docs/repo.md +125 -0
  126. data/docs/rust.md +96 -0
  127. data/docs/sigs.md +167 -0
  128. data/docs/stdlib.md +147 -0
  129. data/docs/syntax.md +940 -0
  130. data/docs/tools.md +17 -0
  131. data/docs/type_fingerprint.md +21 -0
  132. data/docs/wasm_serialization.md +80 -0
  133. data/exe/rbs +7 -0
  134. data/ext/rbs_extension/ast_translation.c +1855 -0
  135. data/ext/rbs_extension/ast_translation.h +41 -0
  136. data/ext/rbs_extension/class_constants.c +187 -0
  137. data/ext/rbs_extension/class_constants.h +104 -0
  138. data/ext/rbs_extension/compat.h +10 -0
  139. data/ext/rbs_extension/extconf.rb +40 -0
  140. data/ext/rbs_extension/legacy_location.c +294 -0
  141. data/ext/rbs_extension/legacy_location.h +82 -0
  142. data/ext/rbs_extension/main.c +613 -0
  143. data/ext/rbs_extension/rbs_extension.h +16 -0
  144. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  145. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  146. data/goodcheck.yml +91 -0
  147. data/include/rbs/ast.h +1047 -0
  148. data/include/rbs/defines.h +99 -0
  149. data/include/rbs/lexer.h +207 -0
  150. data/include/rbs/location.h +40 -0
  151. data/include/rbs/parser.h +153 -0
  152. data/include/rbs/serialize.h +39 -0
  153. data/include/rbs/string.h +47 -0
  154. data/include/rbs/util/rbs_allocator.h +59 -0
  155. data/include/rbs/util/rbs_assert.h +20 -0
  156. data/include/rbs/util/rbs_buffer.h +83 -0
  157. data/include/rbs/util/rbs_constant_pool.h +155 -0
  158. data/include/rbs/util/rbs_encoding.h +282 -0
  159. data/include/rbs/util/rbs_unescape.h +24 -0
  160. data/include/rbs.h +14 -0
  161. data/lib/rbs/ancestor_graph.rb +92 -0
  162. data/lib/rbs/annotate/annotations.rb +199 -0
  163. data/lib/rbs/annotate/formatter.rb +82 -0
  164. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  165. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  166. data/lib/rbs/annotate.rb +8 -0
  167. data/lib/rbs/ast/annotation.rb +29 -0
  168. data/lib/rbs/ast/comment.rb +29 -0
  169. data/lib/rbs/ast/declarations.rb +472 -0
  170. data/lib/rbs/ast/directives.rb +49 -0
  171. data/lib/rbs/ast/members.rb +451 -0
  172. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  173. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  174. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  175. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  176. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  177. data/lib/rbs/ast/ruby/members.rb +762 -0
  178. data/lib/rbs/ast/type_param.rb +235 -0
  179. data/lib/rbs/ast/visitor.rb +137 -0
  180. data/lib/rbs/buffer.rb +189 -0
  181. data/lib/rbs/builtin_names.rb +58 -0
  182. data/lib/rbs/cli/colored_io.rb +48 -0
  183. data/lib/rbs/cli/diff.rb +84 -0
  184. data/lib/rbs/cli/validate.rb +294 -0
  185. data/lib/rbs/cli.rb +1253 -0
  186. data/lib/rbs/collection/cleaner.rb +38 -0
  187. data/lib/rbs/collection/config/lockfile.rb +92 -0
  188. data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
  189. data/lib/rbs/collection/config.rb +81 -0
  190. data/lib/rbs/collection/installer.rb +32 -0
  191. data/lib/rbs/collection/sources/base.rb +14 -0
  192. data/lib/rbs/collection/sources/git.rb +265 -0
  193. data/lib/rbs/collection/sources/local.rb +81 -0
  194. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  195. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  196. data/lib/rbs/collection/sources.rb +38 -0
  197. data/lib/rbs/collection.rb +16 -0
  198. data/lib/rbs/constant.rb +28 -0
  199. data/lib/rbs/definition.rb +415 -0
  200. data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
  201. data/lib/rbs/definition_builder/method_builder.rb +295 -0
  202. data/lib/rbs/definition_builder.rb +1054 -0
  203. data/lib/rbs/diff.rb +131 -0
  204. data/lib/rbs/environment/class_entry.rb +69 -0
  205. data/lib/rbs/environment/module_entry.rb +66 -0
  206. data/lib/rbs/environment/use_map.rb +77 -0
  207. data/lib/rbs/environment.rb +1028 -0
  208. data/lib/rbs/environment_loader.rb +167 -0
  209. data/lib/rbs/environment_walker.rb +155 -0
  210. data/lib/rbs/errors.rb +634 -0
  211. data/lib/rbs/factory.rb +18 -0
  212. data/lib/rbs/file_finder.rb +28 -0
  213. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  214. data/lib/rbs/inline_parser.rb +568 -0
  215. data/lib/rbs/location_aux.rb +170 -0
  216. data/lib/rbs/locator.rb +247 -0
  217. data/lib/rbs/method_type.rb +145 -0
  218. data/lib/rbs/namespace.rb +154 -0
  219. data/lib/rbs/parser/lex_result.rb +15 -0
  220. data/lib/rbs/parser/token.rb +23 -0
  221. data/lib/rbs/parser_aux.rb +142 -0
  222. data/lib/rbs/prototype/helpers.rb +197 -0
  223. data/lib/rbs/prototype/node_usage.rb +99 -0
  224. data/lib/rbs/prototype/rb.rb +816 -0
  225. data/lib/rbs/prototype/rbi.rb +625 -0
  226. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  227. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  228. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  229. data/lib/rbs/prototype/runtime.rb +680 -0
  230. data/lib/rbs/repository.rb +127 -0
  231. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  232. data/lib/rbs/resolver/type_name_resolver.rb +167 -0
  233. data/lib/rbs/rewriter.rb +70 -0
  234. data/lib/rbs/sorter.rb +198 -0
  235. data/lib/rbs/source.rb +99 -0
  236. data/lib/rbs/substitution.rb +83 -0
  237. data/lib/rbs/subtractor.rb +204 -0
  238. data/lib/rbs/test/errors.rb +80 -0
  239. data/lib/rbs/test/guaranteed.rb +30 -0
  240. data/lib/rbs/test/hook.rb +212 -0
  241. data/lib/rbs/test/observer.rb +19 -0
  242. data/lib/rbs/test/setup.rb +84 -0
  243. data/lib/rbs/test/setup_helper.rb +50 -0
  244. data/lib/rbs/test/tester.rb +167 -0
  245. data/lib/rbs/test/type_check.rb +457 -0
  246. data/lib/rbs/test.rb +112 -0
  247. data/lib/rbs/type_alias_dependency.rb +100 -0
  248. data/lib/rbs/type_alias_regularity.rb +126 -0
  249. data/lib/rbs/type_name.rb +122 -0
  250. data/lib/rbs/types.rb +1604 -0
  251. data/lib/rbs/unit_test/convertibles.rb +177 -0
  252. data/lib/rbs/unit_test/spy.rb +138 -0
  253. data/lib/rbs/unit_test/type_assertions.rb +383 -0
  254. data/lib/rbs/unit_test/with_aliases.rb +145 -0
  255. data/lib/rbs/unit_test.rb +6 -0
  256. data/lib/rbs/validator.rb +186 -0
  257. data/lib/rbs/variance_calculator.rb +189 -0
  258. data/lib/rbs/vendorer.rb +71 -0
  259. data/lib/rbs/version.rb +5 -0
  260. data/lib/rbs/wasm/deserializer.rb +213 -0
  261. data/lib/rbs/wasm/jars/asm-analysis.jar +0 -0
  262. data/lib/rbs/wasm/jars/asm-commons.jar +0 -0
  263. data/lib/rbs/wasm/jars/asm-tree.jar +0 -0
  264. data/lib/rbs/wasm/jars/asm-util.jar +0 -0
  265. data/lib/rbs/wasm/jars/asm.jar +0 -0
  266. data/lib/rbs/wasm/jars/compiler.jar +0 -0
  267. data/lib/rbs/wasm/jars/log.jar +0 -0
  268. data/lib/rbs/wasm/jars/runtime.jar +0 -0
  269. data/lib/rbs/wasm/jars/wasi.jar +0 -0
  270. data/lib/rbs/wasm/jars/wasm.jar +0 -0
  271. data/lib/rbs/wasm/location.rb +61 -0
  272. data/lib/rbs/wasm/parser.rb +137 -0
  273. data/lib/rbs/wasm/rbs_parser.wasm +0 -0
  274. data/lib/rbs/wasm/runtime.rb +217 -0
  275. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  276. data/lib/rbs/writer.rb +424 -0
  277. data/lib/rbs.rb +117 -0
  278. data/lib/rdoc/discover.rb +20 -0
  279. data/lib/rdoc_plugin/parser.rb +163 -0
  280. data/rbs.gemspec +68 -0
  281. data/schema/annotation.json +14 -0
  282. data/schema/comment.json +26 -0
  283. data/schema/decls.json +326 -0
  284. data/schema/function.json +87 -0
  285. data/schema/location.json +56 -0
  286. data/schema/members.json +266 -0
  287. data/schema/methodType.json +50 -0
  288. data/schema/typeParam.json +52 -0
  289. data/schema/types.json +317 -0
  290. data/sig/ancestor_builder.rbs +163 -0
  291. data/sig/ancestor_graph.rbs +60 -0
  292. data/sig/annotate/annotations.rbs +102 -0
  293. data/sig/annotate/formatter.rbs +24 -0
  294. data/sig/annotate/rdoc_annotater.rbs +85 -0
  295. data/sig/annotate/rdoc_source.rbs +32 -0
  296. data/sig/annotation.rbs +27 -0
  297. data/sig/ast/ruby/annotations.rbs +470 -0
  298. data/sig/ast/ruby/comment_block.rbs +127 -0
  299. data/sig/ast/ruby/declarations.rbs +158 -0
  300. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  301. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  302. data/sig/ast/ruby/members.rbs +198 -0
  303. data/sig/buffer.rbs +108 -0
  304. data/sig/builtin_names.rbs +44 -0
  305. data/sig/cli/colored_io.rbs +15 -0
  306. data/sig/cli/diff.rbs +15 -0
  307. data/sig/cli/validate.rbs +47 -0
  308. data/sig/cli.rbs +89 -0
  309. data/sig/collection/cleaner.rbs +13 -0
  310. data/sig/collection/config/lockfile.rbs +74 -0
  311. data/sig/collection/config/lockfile_generator.rbs +68 -0
  312. data/sig/collection/config.rbs +46 -0
  313. data/sig/collection/installer.rbs +17 -0
  314. data/sig/collection/sources.rbs +214 -0
  315. data/sig/collection.rbs +4 -0
  316. data/sig/comment.rbs +26 -0
  317. data/sig/constant.rbs +21 -0
  318. data/sig/declarations.rbs +274 -0
  319. data/sig/definition.rbs +232 -0
  320. data/sig/definition_builder.rbs +181 -0
  321. data/sig/diff.rbs +28 -0
  322. data/sig/directives.rbs +77 -0
  323. data/sig/environment/class_entry.rbs +50 -0
  324. data/sig/environment/module_entry.rbs +50 -0
  325. data/sig/environment.rbs +286 -0
  326. data/sig/environment_loader.rbs +111 -0
  327. data/sig/environment_walker.rbs +65 -0
  328. data/sig/errors.rbs +408 -0
  329. data/sig/factory.rbs +5 -0
  330. data/sig/file_finder.rbs +28 -0
  331. data/sig/inline_parser/comment_association.rbs +71 -0
  332. data/sig/inline_parser.rbs +126 -0
  333. data/sig/location.rbs +135 -0
  334. data/sig/locator.rbs +56 -0
  335. data/sig/manifest.yaml +5 -0
  336. data/sig/members.rbs +258 -0
  337. data/sig/method_builder.rbs +89 -0
  338. data/sig/method_types.rbs +58 -0
  339. data/sig/namespace.rbs +161 -0
  340. data/sig/parser.rbs +164 -0
  341. data/sig/prototype/helpers.rbs +29 -0
  342. data/sig/prototype/node_usage.rbs +20 -0
  343. data/sig/prototype/rb.rbs +96 -0
  344. data/sig/prototype/rbi.rbs +75 -0
  345. data/sig/prototype/runtime.rbs +182 -0
  346. data/sig/rbs.rbs +21 -0
  347. data/sig/rdoc/rbs.rbs +67 -0
  348. data/sig/repository.rbs +85 -0
  349. data/sig/resolver/constant_resolver.rbs +92 -0
  350. data/sig/resolver/context.rbs +34 -0
  351. data/sig/resolver/type_name_resolver.rbs +61 -0
  352. data/sig/rewriter.rbs +45 -0
  353. data/sig/shims/bundler.rbs +38 -0
  354. data/sig/shims/enumerable.rbs +5 -0
  355. data/sig/shims/rubygems.rbs +19 -0
  356. data/sig/sorter.rbs +41 -0
  357. data/sig/source.rbs +48 -0
  358. data/sig/substitution.rbs +48 -0
  359. data/sig/subtractor.rbs +37 -0
  360. data/sig/test/errors.rbs +52 -0
  361. data/sig/test/guranteed.rbs +9 -0
  362. data/sig/test/type_check.rbs +19 -0
  363. data/sig/test.rbs +82 -0
  364. data/sig/type_alias_dependency.rbs +53 -0
  365. data/sig/type_alias_regularity.rbs +98 -0
  366. data/sig/type_param.rbs +115 -0
  367. data/sig/typename.rbs +89 -0
  368. data/sig/types.rbs +578 -0
  369. data/sig/unit_test/convertibles.rbs +154 -0
  370. data/sig/unit_test/spy.rbs +22 -0
  371. data/sig/unit_test/type_assertions.rbs +211 -0
  372. data/sig/unit_test/with_aliases.rbs +136 -0
  373. data/sig/use_map.rbs +35 -0
  374. data/sig/util.rbs +9 -0
  375. data/sig/validator.rbs +63 -0
  376. data/sig/variance_calculator.rbs +87 -0
  377. data/sig/vendorer.rbs +51 -0
  378. data/sig/version.rbs +3 -0
  379. data/sig/visitor.rbs +47 -0
  380. data/sig/wasm/deserializer.rbs +66 -0
  381. data/sig/wasm/serialization_schema.rbs +13 -0
  382. data/sig/writer.rbs +127 -0
  383. data/src/ast.c +1628 -0
  384. data/src/lexer.c +3217 -0
  385. data/src/lexer.re +155 -0
  386. data/src/lexstate.c +217 -0
  387. data/src/location.c +31 -0
  388. data/src/parser.c +4255 -0
  389. data/src/serialize.c +958 -0
  390. data/src/string.c +41 -0
  391. data/src/util/rbs_allocator.c +162 -0
  392. data/src/util/rbs_assert.c +19 -0
  393. data/src/util/rbs_buffer.c +54 -0
  394. data/src/util/rbs_constant_pool.c +268 -0
  395. data/src/util/rbs_encoding.c +21308 -0
  396. data/src/util/rbs_unescape.c +167 -0
  397. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  398. data/stdlib/abbrev/0/array.rbs +26 -0
  399. data/stdlib/base64/0/base64.rbs +355 -0
  400. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  401. data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
  402. data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
  403. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  404. data/stdlib/cgi/0/core.rbs +911 -0
  405. data/stdlib/cgi/0/manifest.yaml +4 -0
  406. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  407. data/stdlib/coverage/0/coverage.rbs +266 -0
  408. data/stdlib/csv/0/csv.rbs +3776 -0
  409. data/stdlib/csv/0/manifest.yaml +3 -0
  410. data/stdlib/date/0/date.rbs +1598 -0
  411. data/stdlib/date/0/date_time.rbs +617 -0
  412. data/stdlib/date/0/time.rbs +26 -0
  413. data/stdlib/dbm/0/dbm.rbs +421 -0
  414. data/stdlib/delegate/0/delegator.rbs +187 -0
  415. data/stdlib/delegate/0/kernel.rbs +47 -0
  416. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  417. data/stdlib/did_you_mean/0/did_you_mean.rbs +344 -0
  418. data/stdlib/digest/0/digest.rbs +687 -0
  419. data/stdlib/erb/0/erb.rbs +933 -0
  420. data/stdlib/etc/0/etc.rbs +884 -0
  421. data/stdlib/fileutils/0/fileutils.rbs +1753 -0
  422. data/stdlib/find/0/find.rbs +49 -0
  423. data/stdlib/forwardable/0/forwardable.rbs +271 -0
  424. data/stdlib/io-console/0/io-console.rbs +414 -0
  425. data/stdlib/ipaddr/0/ipaddr.rbs +436 -0
  426. data/stdlib/json/0/json.rbs +1963 -0
  427. data/stdlib/kconv/0/kconv.rbs +166 -0
  428. data/stdlib/logger/0/formatter.rbs +45 -0
  429. data/stdlib/logger/0/log_device.rbs +100 -0
  430. data/stdlib/logger/0/logger.rbs +796 -0
  431. data/stdlib/logger/0/manifest.yaml +2 -0
  432. data/stdlib/logger/0/period.rbs +17 -0
  433. data/stdlib/logger/0/severity.rbs +34 -0
  434. data/stdlib/minitest/0/kernel.rbs +42 -0
  435. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  436. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  437. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  438. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  439. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  440. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  441. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  442. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  443. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  444. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  445. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  446. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  447. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  448. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  449. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  450. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  451. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  452. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  453. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  454. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  455. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  456. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  457. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  458. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  459. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  460. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  461. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  462. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  463. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  464. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  465. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  466. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  467. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  468. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  469. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  470. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  471. data/stdlib/minitest/0/minitest.rbs +115 -0
  472. data/stdlib/monitor/0/monitor.rbs +363 -0
  473. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  474. data/stdlib/net-http/0/manifest.yaml +3 -0
  475. data/stdlib/net-http/0/net-http.rbs +5580 -0
  476. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  477. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  478. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  479. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  480. data/stdlib/nkf/0/nkf.rbs +402 -0
  481. data/stdlib/objspace/0/objspace.rbs +470 -0
  482. data/stdlib/observable/0/observable.rbs +217 -0
  483. data/stdlib/open-uri/0/manifest.yaml +4 -0
  484. data/stdlib/open-uri/0/open-uri.rbs +433 -0
  485. data/stdlib/open3/0/open3.rbs +606 -0
  486. data/stdlib/openssl/0/manifest.yaml +3 -0
  487. data/stdlib/openssl/0/openssl.rbs +12231 -0
  488. data/stdlib/optparse/0/optparse.rbs +1734 -0
  489. data/stdlib/pathname/0/pathname.rbs +36 -0
  490. data/stdlib/pp/0/manifest.yaml +2 -0
  491. data/stdlib/pp/0/pp.rbs +301 -0
  492. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  493. data/stdlib/pstore/0/pstore.rbs +608 -0
  494. data/stdlib/psych/0/core_ext.rbs +12 -0
  495. data/stdlib/psych/0/dbm.rbs +237 -0
  496. data/stdlib/psych/0/manifest.yaml +3 -0
  497. data/stdlib/psych/0/psych.rbs +455 -0
  498. data/stdlib/psych/0/store.rbs +57 -0
  499. data/stdlib/pty/0/pty.rbs +240 -0
  500. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  501. data/stdlib/rdoc/0/code_object.rbs +52 -0
  502. data/stdlib/rdoc/0/comment.rbs +61 -0
  503. data/stdlib/rdoc/0/context.rbs +153 -0
  504. data/stdlib/rdoc/0/markup.rbs +117 -0
  505. data/stdlib/rdoc/0/options.rbs +76 -0
  506. data/stdlib/rdoc/0/parser.rbs +56 -0
  507. data/stdlib/rdoc/0/rdoc.rbs +393 -0
  508. data/stdlib/rdoc/0/ri.rbs +17 -0
  509. data/stdlib/rdoc/0/store.rbs +48 -0
  510. data/stdlib/rdoc/0/top_level.rbs +97 -0
  511. data/stdlib/resolv/0/manifest.yaml +3 -0
  512. data/stdlib/resolv/0/resolv.rbs +1787 -0
  513. data/stdlib/ripper/0/ripper.rbs +1654 -0
  514. data/stdlib/securerandom/0/manifest.yaml +2 -0
  515. data/stdlib/securerandom/0/securerandom.rbs +49 -0
  516. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  517. data/stdlib/singleton/0/singleton.rbs +134 -0
  518. data/stdlib/socket/0/addrinfo.rbs +666 -0
  519. data/stdlib/socket/0/basic_socket.rbs +590 -0
  520. data/stdlib/socket/0/constants.rbs +2295 -0
  521. data/stdlib/socket/0/ip_socket.rbs +94 -0
  522. data/stdlib/socket/0/socket.rbs +4170 -0
  523. data/stdlib/socket/0/socket_error.rbs +5 -0
  524. data/stdlib/socket/0/tcp_server.rbs +192 -0
  525. data/stdlib/socket/0/tcp_socket.rbs +87 -0
  526. data/stdlib/socket/0/udp_socket.rbs +133 -0
  527. data/stdlib/socket/0/unix_server.rbs +169 -0
  528. data/stdlib/socket/0/unix_socket.rbs +172 -0
  529. data/stdlib/stringio/0/stringio.rbs +1681 -0
  530. data/stdlib/strscan/0/string_scanner.rbs +1648 -0
  531. data/stdlib/tempfile/0/tempfile.rbs +483 -0
  532. data/stdlib/time/0/time.rbs +434 -0
  533. data/stdlib/timeout/0/timeout.rbs +137 -0
  534. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  535. data/stdlib/tsort/0/cyclic.rbs +8 -0
  536. data/stdlib/tsort/0/interfaces.rbs +20 -0
  537. data/stdlib/tsort/0/tsort.rbs +410 -0
  538. data/stdlib/uri/0/common.rbs +621 -0
  539. data/stdlib/uri/0/file.rbs +118 -0
  540. data/stdlib/uri/0/ftp.rbs +13 -0
  541. data/stdlib/uri/0/generic.rbs +1116 -0
  542. data/stdlib/uri/0/http.rbs +104 -0
  543. data/stdlib/uri/0/https.rbs +14 -0
  544. data/stdlib/uri/0/ldap.rbs +230 -0
  545. data/stdlib/uri/0/ldaps.rbs +14 -0
  546. data/stdlib/uri/0/mailto.rbs +92 -0
  547. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  548. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  549. data/stdlib/uri/0/ws.rbs +13 -0
  550. data/stdlib/uri/0/wss.rbs +9 -0
  551. data/stdlib/yaml/0/manifest.yaml +2 -0
  552. data/stdlib/yaml/0/yaml.rbs +1 -0
  553. data/stdlib/zlib/0/buf_error.rbs +10 -0
  554. data/stdlib/zlib/0/data_error.rbs +10 -0
  555. data/stdlib/zlib/0/deflate.rbs +211 -0
  556. data/stdlib/zlib/0/error.rbs +20 -0
  557. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  558. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  559. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  560. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  561. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  562. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  563. data/stdlib/zlib/0/gzip_writer.rbs +168 -0
  564. data/stdlib/zlib/0/inflate.rbs +180 -0
  565. data/stdlib/zlib/0/mem_error.rbs +10 -0
  566. data/stdlib/zlib/0/need_dict.rbs +13 -0
  567. data/stdlib/zlib/0/stream_end.rbs +11 -0
  568. data/stdlib/zlib/0/stream_error.rbs +11 -0
  569. data/stdlib/zlib/0/version_error.rbs +11 -0
  570. data/stdlib/zlib/0/zlib.rbs +449 -0
  571. data/stdlib/zlib/0/zstream.rbs +201 -0
  572. data/wasm/README.md +59 -0
  573. data/wasm/rbs_wasm.c +411 -0
  574. metadata +660 -0
data/core/thread.rbs ADDED
@@ -0,0 +1,1826 @@
1
+ # <!-- rdoc-file=vm.c -->
2
+ # Threads are the Ruby implementation for a concurrent programming model.
3
+ #
4
+ # Programs that require multiple threads of execution are a perfect candidate
5
+ # for Ruby's Thread class.
6
+ #
7
+ # For example, we can create a new thread separate from the main thread's
8
+ # execution using ::new.
9
+ #
10
+ # thr = Thread.new { puts "What's the big deal" }
11
+ #
12
+ # Then we are able to pause the execution of the main thread and allow our new
13
+ # thread to finish, using #join:
14
+ #
15
+ # thr.join #=> "What's the big deal"
16
+ #
17
+ # If we don't call <code>thr.join</code> before the main thread terminates, then
18
+ # all other threads including `thr` will be killed.
19
+ #
20
+ # Alternatively, you can use an array for handling multiple threads at once,
21
+ # like in the following example:
22
+ #
23
+ # threads = []
24
+ # threads << Thread.new { puts "What's the big deal" }
25
+ # threads << Thread.new { 3.times { puts "Threads are fun!" } }
26
+ #
27
+ # After creating a few threads we wait for them all to finish consecutively.
28
+ #
29
+ # threads.each { |thr| thr.join }
30
+ #
31
+ # To retrieve the last value of a thread, use #value
32
+ #
33
+ # thr = Thread.new { sleep 1; "Useful value" }
34
+ # thr.value #=> "Useful value"
35
+ #
36
+ # ### Thread initialization
37
+ #
38
+ # In order to create new threads, Ruby provides ::new, ::start, and ::fork. A
39
+ # block must be provided with each of these methods, otherwise a ThreadError
40
+ # will be raised.
41
+ #
42
+ # When subclassing the Thread class, the `initialize` method of your subclass
43
+ # will be ignored by ::start and ::fork. Otherwise, be sure to call super in
44
+ # your `initialize` method.
45
+ #
46
+ # ### Thread termination
47
+ #
48
+ # For terminating threads, Ruby provides a variety of ways to do this.
49
+ #
50
+ # The class method ::kill, is meant to exit a given thread:
51
+ #
52
+ # thr = Thread.new { sleep }
53
+ # Thread.kill(thr) # sends exit() to thr
54
+ #
55
+ # Alternatively, you can use the instance method #exit, or any of its aliases
56
+ # #kill or #terminate.
57
+ #
58
+ # thr.exit
59
+ #
60
+ # ### Thread status
61
+ #
62
+ # Ruby provides a few instance methods for querying the state of a given thread.
63
+ # To get a string with the current thread's state use #status
64
+ #
65
+ # thr = Thread.new { sleep }
66
+ # thr.status # => "sleep"
67
+ # thr.exit
68
+ # thr.status # => false
69
+ #
70
+ # You can also use #alive? to tell if the thread is running or sleeping, and
71
+ # #stop? if the thread is dead or sleeping.
72
+ #
73
+ # ### Thread variables and scope
74
+ #
75
+ # Since threads are created with blocks, the same rules apply to other Ruby
76
+ # blocks for variable scope. Any local variables created within this block are
77
+ # accessible to only this thread.
78
+ #
79
+ # #### Fiber-local vs. Thread-local
80
+ #
81
+ # Each fiber has its own bucket for Thread#[] storage. When you set a new
82
+ # fiber-local it is only accessible within this Fiber. To illustrate:
83
+ #
84
+ # Thread.new {
85
+ # Thread.current[:foo] = "bar"
86
+ # Fiber.new {
87
+ # p Thread.current[:foo] # => nil
88
+ # }.resume
89
+ # }.join
90
+ #
91
+ # This example uses #[] for getting and #[]= for setting fiber-locals, you can
92
+ # also use #keys to list the fiber-locals for a given thread and #key? to check
93
+ # if a fiber-local exists.
94
+ #
95
+ # When it comes to thread-locals, they are accessible within the entire scope of
96
+ # the thread. Given the following example:
97
+ #
98
+ # Thread.new{
99
+ # Thread.current.thread_variable_set(:foo, 1)
100
+ # p Thread.current.thread_variable_get(:foo) # => 1
101
+ # Fiber.new{
102
+ # Thread.current.thread_variable_set(:foo, 2)
103
+ # p Thread.current.thread_variable_get(:foo) # => 2
104
+ # }.resume
105
+ # p Thread.current.thread_variable_get(:foo) # => 2
106
+ # }.join
107
+ #
108
+ # You can see that the thread-local <code>:foo</code> carried over into the
109
+ # fiber and was changed to `2` by the end of the thread.
110
+ #
111
+ # This example makes use of #thread_variable_set to create new thread-locals,
112
+ # and #thread_variable_get to reference them.
113
+ #
114
+ # There is also #thread_variables to list all thread-locals, and
115
+ # #thread_variable? to check if a given thread-local exists.
116
+ #
117
+ # ### Exception handling
118
+ #
119
+ # When an unhandled exception is raised inside a thread, it will terminate. By
120
+ # default, this exception will not propagate to other threads. The exception is
121
+ # stored and when another thread calls #value or #join, the exception will be
122
+ # re-raised in that thread.
123
+ #
124
+ # t = Thread.new{ raise 'something went wrong' }
125
+ # t.value #=> RuntimeError: something went wrong
126
+ #
127
+ # An exception can be raised from outside the thread using the Thread#raise
128
+ # instance method, which takes the same parameters as Kernel#raise.
129
+ #
130
+ # Setting Thread.abort_on_exception = true, Thread#abort_on_exception = true, or
131
+ # $DEBUG = true will cause a subsequent unhandled exception raised in a thread
132
+ # to be automatically re-raised in the main thread.
133
+ #
134
+ # With the addition of the class method ::handle_interrupt, you can now handle
135
+ # exceptions asynchronously with threads.
136
+ #
137
+ # ### Scheduling
138
+ #
139
+ # Ruby provides a few ways to support scheduling threads in your program.
140
+ #
141
+ # The first way is by using the class method ::stop, to put the current running
142
+ # thread to sleep and schedule the execution of another thread.
143
+ #
144
+ # Once a thread is asleep, you can use the instance method #wakeup to mark your
145
+ # thread as eligible for scheduling.
146
+ #
147
+ # You can also try ::pass, which attempts to pass execution to another thread
148
+ # but is dependent on the OS whether a running thread will switch or not. The
149
+ # same goes for #priority, which lets you hint to the thread scheduler which
150
+ # threads you want to take precedence when passing execution. This method is
151
+ # also dependent on the OS and may be ignored on some platforms.
152
+ #
153
+ class Thread < Object
154
+ # <!--
155
+ # rdoc-file=thread.c
156
+ # - Thread.current -> thread
157
+ # -->
158
+ # Returns the currently executing thread.
159
+ #
160
+ # Thread.current #=> #<Thread:0x401bdf4c run>
161
+ #
162
+ def self.current: () -> Thread
163
+
164
+ # <!--
165
+ # rdoc-file=thread.c
166
+ # - Thread.main -> thread
167
+ # -->
168
+ # Returns the main thread.
169
+ #
170
+ def self.main: () -> Thread
171
+
172
+ # <!--
173
+ # rdoc-file=thread.c
174
+ # - thr[sym] -> obj or nil
175
+ # -->
176
+ # Attribute Reference---Returns the value of a fiber-local variable (current
177
+ # thread's root fiber if not explicitly inside a Fiber), using either a symbol
178
+ # or a string name. If the specified variable does not exist, returns `nil`.
179
+ #
180
+ # [
181
+ # Thread.new { Thread.current["name"] = "A" },
182
+ # Thread.new { Thread.current[:name] = "B" },
183
+ # Thread.new { Thread.current["name"] = "C" }
184
+ # ].each do |th|
185
+ # th.join
186
+ # puts "#{th.inspect}: #{th[:name]}"
187
+ # end
188
+ #
189
+ # This will produce:
190
+ #
191
+ # #<Thread:0x00000002a54220 dead>: A
192
+ # #<Thread:0x00000002a541a8 dead>: B
193
+ # #<Thread:0x00000002a54130 dead>: C
194
+ #
195
+ # Thread#[] and Thread#[]= are not thread-local but fiber-local. This confusion
196
+ # did not exist in Ruby 1.8 because fibers are only available since Ruby 1.9.
197
+ # Ruby 1.9 chooses that the methods behaves fiber-local to save following idiom
198
+ # for dynamic scope.
199
+ #
200
+ # def meth(newvalue)
201
+ # begin
202
+ # oldvalue = Thread.current[:name]
203
+ # Thread.current[:name] = newvalue
204
+ # yield
205
+ # ensure
206
+ # Thread.current[:name] = oldvalue
207
+ # end
208
+ # end
209
+ #
210
+ # The idiom may not work as dynamic scope if the methods are thread-local and a
211
+ # given block switches fiber.
212
+ #
213
+ # f = Fiber.new {
214
+ # meth(1) {
215
+ # Fiber.yield
216
+ # }
217
+ # }
218
+ # meth(2) {
219
+ # f.resume
220
+ # }
221
+ # f.resume
222
+ # p Thread.current[:name]
223
+ # #=> nil if fiber-local
224
+ # #=> 2 if thread-local (The value 2 is leaked to outside of meth method.)
225
+ #
226
+ # For thread-local variables, please see #thread_variable_get and
227
+ # #thread_variable_set.
228
+ #
229
+ def []: (interned key) -> untyped
230
+
231
+ # <!--
232
+ # rdoc-file=thread.c
233
+ # - thr[sym] = obj -> obj
234
+ # -->
235
+ # Attribute Assignment---Sets or creates the value of a fiber-local variable,
236
+ # using either a symbol or a string.
237
+ #
238
+ # See also Thread#[].
239
+ #
240
+ # For thread-local variables, please see #thread_variable_set and
241
+ # #thread_variable_get.
242
+ #
243
+ def []=: (interned key, untyped value) -> untyped
244
+
245
+ # <!--
246
+ # rdoc-file=thread.c
247
+ # - thr.alive? -> true or false
248
+ # -->
249
+ # Returns `true` if `thr` is running or sleeping.
250
+ #
251
+ # thr = Thread.new { }
252
+ # thr.join #=> #<Thread:0x401b3fb0 dead>
253
+ # Thread.current.alive? #=> true
254
+ # thr.alive? #=> false
255
+ #
256
+ # See also #stop? and #status.
257
+ #
258
+ def alive?: () -> bool
259
+
260
+ # <!--
261
+ # rdoc-file=thread.c
262
+ # - thr.exit -> thr
263
+ # - thr.kill -> thr
264
+ # - thr.terminate -> thr
265
+ # -->
266
+ # Terminates `thr` and schedules another thread to be run, returning the
267
+ # terminated Thread. If this is the main thread, or the last thread, exits the
268
+ # process. Note that the caller does not wait for the thread to terminate if the
269
+ # receiver is different from the currently running thread. The termination is
270
+ # asynchronous, and the thread can still run a small amount of ruby code before
271
+ # exiting.
272
+ #
273
+ def kill: () -> Thread?
274
+
275
+ # <!--
276
+ # rdoc-file=thread.c
277
+ # - thr.abort_on_exception -> true or false
278
+ # -->
279
+ # Returns the status of the thread-local ``abort on exception'' condition for
280
+ # this `thr`.
281
+ #
282
+ # The default is `false`.
283
+ #
284
+ # See also #abort_on_exception=.
285
+ #
286
+ # There is also a class level method to set this for all threads, see
287
+ # ::abort_on_exception.
288
+ #
289
+ def abort_on_exception: () -> bool
290
+
291
+ # <!--
292
+ # rdoc-file=thread.c
293
+ # - thr.abort_on_exception= boolean -> true or false
294
+ # -->
295
+ # When set to `true`, if this `thr` is aborted by an exception, the raised
296
+ # exception will be re-raised in the main thread.
297
+ #
298
+ # See also #abort_on_exception.
299
+ #
300
+ # There is also a class level method to set this for all threads, see
301
+ # ::abort_on_exception=.
302
+ #
303
+ def abort_on_exception=: (boolish abort_on_exception) -> untyped
304
+
305
+ # <!--
306
+ # rdoc-file=vm_trace.c
307
+ # - thr.add_trace_func(proc) -> proc
308
+ # -->
309
+ # Adds *proc* as a handler for tracing.
310
+ #
311
+ # See Thread#set_trace_func and Kernel#set_trace_func.
312
+ #
313
+ def add_trace_func: (untyped proc) -> untyped
314
+
315
+ # <!--
316
+ # rdoc-file=thread.c
317
+ # - thread.backtrace -> array or nil
318
+ # -->
319
+ # Returns the current backtrace of the target thread.
320
+ #
321
+ def backtrace: (*untyped args) -> ::Array[untyped]
322
+
323
+ # <!--
324
+ # rdoc-file=thread.c
325
+ # - thread.backtrace_locations(*args) -> array or nil
326
+ # -->
327
+ # Returns the execution stack for the target thread---an array containing
328
+ # backtrace location objects.
329
+ #
330
+ # See Thread::Backtrace::Location for more information.
331
+ #
332
+ # This method behaves similarly to Kernel#caller_locations except it applies to
333
+ # a specific thread.
334
+ #
335
+ def backtrace_locations: (*untyped args) -> ::Array[untyped]?
336
+
337
+ # <!-- rdoc-file=thread.c -->
338
+ # Terminates `thr` and schedules another thread to be run, returning the
339
+ # terminated Thread. If this is the main thread, or the last thread, exits the
340
+ # process. Note that the caller does not wait for the thread to terminate if the
341
+ # receiver is different from the currently running thread. The termination is
342
+ # asynchronous, and the thread can still run a small amount of ruby code before
343
+ # exiting.
344
+ #
345
+ def exit: () -> Thread?
346
+
347
+ # <!--
348
+ # rdoc-file=thread.c
349
+ # - thr.fetch(sym) -> obj
350
+ # - thr.fetch(sym) { } -> obj
351
+ # - thr.fetch(sym, default) -> obj
352
+ # -->
353
+ # Returns a fiber-local for the given key. If the key can't be found, there are
354
+ # several options: With no other arguments, it will raise a KeyError exception;
355
+ # if *default* is given, then that will be returned; if the optional code block
356
+ # is specified, then that will be run and its result returned. See Thread#[]
357
+ # and Hash#fetch.
358
+ #
359
+ def fetch: (*untyped sym) -> untyped
360
+
361
+ # <!--
362
+ # rdoc-file=thread.c
363
+ # - thr.group -> thgrp or nil
364
+ # -->
365
+ # Returns the ThreadGroup which contains the given thread.
366
+ #
367
+ # Thread.main.group #=> #<ThreadGroup:0x4029d914>
368
+ #
369
+ def group: () -> ThreadGroup?
370
+
371
+ # <!--
372
+ # rdoc-file=thread.c
373
+ # - Thread.new { ... } -> thread
374
+ # - Thread.new(*args, &proc) -> thread
375
+ # - Thread.new(*args) { |args| ... } -> thread
376
+ # -->
377
+ # Creates a new thread executing the given block.
378
+ #
379
+ # Any `args` given to ::new will be passed to the block:
380
+ #
381
+ # arr = []
382
+ # a, b, c = 1, 2, 3
383
+ # Thread.new(a,b,c) { |d,e,f| arr << d << e << f }.join
384
+ # arr #=> [1, 2, 3]
385
+ #
386
+ # A ThreadError exception is raised if ::new is called without a block.
387
+ #
388
+ # If you're going to subclass Thread, be sure to call super in your `initialize`
389
+ # method, otherwise a ThreadError will be raised.
390
+ #
391
+ def initialize: (*untyped) { (?) -> void } -> void
392
+
393
+ # <!--
394
+ # rdoc-file=thread.c
395
+ # - thr.join -> thr
396
+ # - thr.join(limit) -> thr
397
+ # -->
398
+ # The calling thread will suspend execution and run this `thr`.
399
+ #
400
+ # Does not return until `thr` exits or until the given `limit` seconds have
401
+ # passed.
402
+ #
403
+ # If the time limit expires, `nil` will be returned, otherwise `thr` is
404
+ # returned.
405
+ #
406
+ # Any threads not joined will be killed when the main program exits.
407
+ #
408
+ # If `thr` had previously raised an exception and the ::abort_on_exception or
409
+ # $DEBUG flags are not set, (so the exception has not yet been processed), it
410
+ # will be processed at this time.
411
+ #
412
+ # a = Thread.new { print "a"; sleep(10); print "b"; print "c" }
413
+ # x = Thread.new { print "x"; Thread.pass; print "y"; print "z" }
414
+ # x.join # Let thread x finish, thread a will be killed on exit.
415
+ # #=> "axyz"
416
+ #
417
+ # The following example illustrates the `limit` parameter.
418
+ #
419
+ # y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }}
420
+ # puts "Waiting" until y.join(0.15)
421
+ #
422
+ # This will produce:
423
+ #
424
+ # tick...
425
+ # Waiting
426
+ # tick...
427
+ # Waiting
428
+ # tick...
429
+ # tick...
430
+ #
431
+ def join: (*untyped limit) -> Thread
432
+
433
+ # <!--
434
+ # rdoc-file=thread.c
435
+ # - thr.key?(sym) -> true or false
436
+ # -->
437
+ # Returns `true` if the given string (or symbol) exists as a fiber-local
438
+ # variable.
439
+ #
440
+ # me = Thread.current
441
+ # me[:oliver] = "a"
442
+ # me.key?(:oliver) #=> true
443
+ # me.key?(:stanley) #=> false
444
+ #
445
+ def key?: (Symbol sym) -> bool
446
+
447
+ # <!--
448
+ # rdoc-file=thread.c
449
+ # - thr.keys -> array
450
+ # -->
451
+ # Returns an array of the names of the fiber-local variables (as Symbols).
452
+ #
453
+ # thr = Thread.new do
454
+ # Thread.current[:cat] = 'meow'
455
+ # Thread.current["dog"] = 'woof'
456
+ # end
457
+ # thr.join #=> #<Thread:0x401b3f10 dead>
458
+ # thr.keys #=> [:dog, :cat]
459
+ #
460
+ def keys: () -> ::Array[Symbol]
461
+
462
+ # <!--
463
+ # rdoc-file=thread.c
464
+ # - thr.name -> string
465
+ # -->
466
+ # show the name of the thread.
467
+ #
468
+ def name: () -> String
469
+
470
+ # <!--
471
+ # rdoc-file=thread.c
472
+ # - thr.name=(name) -> string
473
+ # -->
474
+ # set given name to the ruby thread. On some platform, it may set the name to
475
+ # pthread and/or kernel.
476
+ #
477
+ def name=: (untyped name) -> untyped
478
+
479
+ # <!--
480
+ # rdoc-file=thread.c
481
+ # - thr.native_thread_id -> integer
482
+ # -->
483
+ # Return the native thread ID which is used by the Ruby thread.
484
+ #
485
+ # The ID depends on the OS. (not POSIX thread ID returned by pthread_self(3))
486
+ # * On Linux it is TID returned by gettid(2).
487
+ # * On macOS it is the system-wide unique integral ID of thread returned by
488
+ # pthread_threadid_np(3).
489
+ # * On FreeBSD it is the unique integral ID of the thread returned by
490
+ # pthread_getthreadid_np(3).
491
+ # * On Windows it is the thread identifier returned by GetThreadId().
492
+ # * On other platforms, it raises NotImplementedError.
493
+ #
494
+ # NOTE: If the thread is not associated yet or already deassociated with a
495
+ # native thread, it returns *nil*. If the Ruby implementation uses M:N thread
496
+ # model, the ID may change depending on the timing.
497
+ #
498
+ def native_thread_id: () -> Integer
499
+
500
+ # <!--
501
+ # rdoc-file=thread.c
502
+ # - target_thread.pending_interrupt?(error = nil) -> true/false
503
+ # -->
504
+ # Returns whether or not the asynchronous queue is empty for the target thread.
505
+ #
506
+ # If `error` is given, then check only for `error` type deferred events.
507
+ #
508
+ # See ::pending_interrupt? for more information.
509
+ #
510
+ def pending_interrupt?: (*untyped args) -> bool
511
+
512
+ # <!--
513
+ # rdoc-file=thread.c
514
+ # - thr.priority -> integer
515
+ # -->
516
+ # Returns the priority of *thr*. Default is inherited from the current thread
517
+ # which creating the new thread, or zero for the initial main thread;
518
+ # higher-priority thread will run more frequently than lower-priority threads
519
+ # (but lower-priority threads can also run).
520
+ #
521
+ # This is just hint for Ruby thread scheduler. It may be ignored on some
522
+ # platform.
523
+ #
524
+ # Thread.current.priority #=> 0
525
+ #
526
+ def priority: () -> Integer
527
+
528
+ # <!--
529
+ # rdoc-file=thread.c
530
+ # - thr.priority= integer -> thr
531
+ # -->
532
+ # Sets the priority of *thr* to *integer*. Higher-priority threads will run more
533
+ # frequently than lower-priority threads (but lower-priority threads can also
534
+ # run).
535
+ #
536
+ # This is just hint for Ruby thread scheduler. It may be ignored on some
537
+ # platform.
538
+ #
539
+ # count1 = count2 = 0
540
+ # a = Thread.new do
541
+ # loop { count1 += 1 }
542
+ # end
543
+ # a.priority = -1
544
+ #
545
+ # b = Thread.new do
546
+ # loop { count2 += 1 }
547
+ # end
548
+ # b.priority = -2
549
+ # sleep 1 #=> 1
550
+ # count1 #=> 622504
551
+ # count2 #=> 5832
552
+ #
553
+ def priority=: (Integer priority) -> untyped
554
+
555
+ # <!--
556
+ # rdoc-file=thread.c
557
+ # - thr.report_on_exception -> true or false
558
+ # -->
559
+ # Returns the status of the thread-local ``report on exception'' condition for
560
+ # this `thr`.
561
+ #
562
+ # The default value when creating a Thread is the value of the global flag
563
+ # Thread.report_on_exception.
564
+ #
565
+ # See also #report_on_exception=.
566
+ #
567
+ # There is also a class level method to set this for all new threads, see
568
+ # ::report_on_exception=.
569
+ #
570
+ def report_on_exception: () -> bool
571
+
572
+ # <!--
573
+ # rdoc-file=thread.c
574
+ # - thr.report_on_exception= boolean -> true or false
575
+ # -->
576
+ # When set to `true`, a message is printed on $stderr if an exception kills this
577
+ # `thr`. See ::report_on_exception for details.
578
+ #
579
+ # See also #report_on_exception.
580
+ #
581
+ # There is also a class level method to set this for all new threads, see
582
+ # ::report_on_exception=.
583
+ #
584
+ def report_on_exception=: (boolish report_on_exception) -> untyped
585
+
586
+ # <!--
587
+ # rdoc-file=thread.c
588
+ # - thr.run -> thr
589
+ # -->
590
+ # Wakes up `thr`, making it eligible for scheduling.
591
+ #
592
+ # a = Thread.new { puts "a"; Thread.stop; puts "c" }
593
+ # sleep 0.1 while a.status!='sleep'
594
+ # puts "Got here"
595
+ # a.run
596
+ # a.join
597
+ #
598
+ # This will produce:
599
+ #
600
+ # a
601
+ # Got here
602
+ # c
603
+ #
604
+ # See also the instance method #wakeup.
605
+ #
606
+ def run: () -> Thread
607
+
608
+ # Returns the safe level.
609
+ #
610
+ # This method is obsolete because $SAFE is a process global state. Simply
611
+ # check $SAFE.
612
+ def safe_level: () -> Integer
613
+
614
+ # <!--
615
+ # rdoc-file=thread.c
616
+ # - thr.status -> string, false or nil
617
+ # -->
618
+ # Returns the status of `thr`.
619
+ #
620
+ # <code>"sleep"</code>
621
+ # : Returned if this thread is sleeping or waiting on I/O
622
+ #
623
+ # <code>"run"</code>
624
+ # : When this thread is executing
625
+ #
626
+ # <code>"aborting"</code>
627
+ # : If this thread is aborting
628
+ #
629
+ # `false`
630
+ # : When this thread is terminated normally
631
+ #
632
+ # `nil`
633
+ # : If terminated with an exception.
634
+ #
635
+ #
636
+ # a = Thread.new { raise("die now") }
637
+ # b = Thread.new { Thread.stop }
638
+ # c = Thread.new { Thread.exit }
639
+ # d = Thread.new { sleep }
640
+ # d.kill #=> #<Thread:0x401b3678 aborting>
641
+ # a.status #=> nil
642
+ # b.status #=> "sleep"
643
+ # c.status #=> false
644
+ # d.status #=> "aborting"
645
+ # Thread.current.status #=> "run"
646
+ #
647
+ # See also the instance methods #alive? and #stop?
648
+ #
649
+ def status: () -> (String | bool)?
650
+
651
+ # <!--
652
+ # rdoc-file=thread.c
653
+ # - thr.stop? -> true or false
654
+ # -->
655
+ # Returns `true` if `thr` is dead or sleeping.
656
+ #
657
+ # a = Thread.new { Thread.stop }
658
+ # b = Thread.current
659
+ # a.stop? #=> true
660
+ # b.stop? #=> false
661
+ #
662
+ # See also #alive? and #status.
663
+ #
664
+ def stop?: () -> bool
665
+
666
+ # <!-- rdoc-file=thread.c -->
667
+ # Terminates `thr` and schedules another thread to be run, returning the
668
+ # terminated Thread. If this is the main thread, or the last thread, exits the
669
+ # process. Note that the caller does not wait for the thread to terminate if the
670
+ # receiver is different from the currently running thread. The termination is
671
+ # asynchronous, and the thread can still run a small amount of ruby code before
672
+ # exiting.
673
+ #
674
+ def terminate: () -> Thread?
675
+
676
+ # <!--
677
+ # rdoc-file=thread.c
678
+ # - thr.thread_variable?(key) -> true or false
679
+ # -->
680
+ # Returns `true` if the given string (or symbol) exists as a thread-local
681
+ # variable.
682
+ #
683
+ # me = Thread.current
684
+ # me.thread_variable_set(:oliver, "a")
685
+ # me.thread_variable?(:oliver) #=> true
686
+ # me.thread_variable?(:stanley) #=> false
687
+ #
688
+ # Note that these are not fiber local variables. Please see Thread#[] and
689
+ # Thread#thread_variable_get for more details.
690
+ #
691
+ def thread_variable?: (interned key) -> bool
692
+
693
+ # <!--
694
+ # rdoc-file=thread.c
695
+ # - thr.thread_variable_get(key) -> obj or nil
696
+ # -->
697
+ # Returns the value of a thread local variable that has been set. Note that
698
+ # these are different than fiber local values. For fiber local values, please
699
+ # see Thread#[] and Thread#[]=.
700
+ #
701
+ # Thread local values are carried along with threads, and do not respect fibers.
702
+ # For example:
703
+ #
704
+ # Thread.new {
705
+ # Thread.current.thread_variable_set("foo", "bar") # set a thread local
706
+ # Thread.current["foo"] = "bar" # set a fiber local
707
+ #
708
+ # Fiber.new {
709
+ # Fiber.yield [
710
+ # Thread.current.thread_variable_get("foo"), # get the thread local
711
+ # Thread.current["foo"], # get the fiber local
712
+ # ]
713
+ # }.resume
714
+ # }.join.value # => ['bar', nil]
715
+ #
716
+ # The value "bar" is returned for the thread local, where nil is returned for
717
+ # the fiber local. The fiber is executed in the same thread, so the thread
718
+ # local values are available.
719
+ #
720
+ def thread_variable_get: (untyped key) -> untyped
721
+
722
+ # <!--
723
+ # rdoc-file=thread.c
724
+ # - thr.thread_variable_set(key, value)
725
+ # -->
726
+ # Sets a thread local with `key` to `value`. Note that these are local to
727
+ # threads, and not to fibers. Please see Thread#thread_variable_get and
728
+ # Thread#[] for more information.
729
+ #
730
+ def thread_variable_set: (untyped key, untyped value) -> untyped
731
+
732
+ # <!--
733
+ # rdoc-file=thread.c
734
+ # - thr.thread_variables -> array
735
+ # -->
736
+ # Returns an array of the names of the thread-local variables (as Symbols).
737
+ #
738
+ # thr = Thread.new do
739
+ # Thread.current.thread_variable_set(:cat, 'meow')
740
+ # Thread.current.thread_variable_set("dog", 'woof')
741
+ # end
742
+ # thr.join #=> #<Thread:0x401b3f10 dead>
743
+ # thr.thread_variables #=> [:dog, :cat]
744
+ #
745
+ # Note that these are not fiber local variables. Please see Thread#[] and
746
+ # Thread#thread_variable_get for more details.
747
+ #
748
+ def thread_variables: () -> ::Array[Symbol]
749
+
750
+ # <!--
751
+ # rdoc-file=thread.c
752
+ # - thr.value -> obj
753
+ # -->
754
+ # Waits for `thr` to complete, using #join, and returns its value or raises the
755
+ # exception which terminated the thread.
756
+ #
757
+ # a = Thread.new { 2 + 2 }
758
+ # a.value #=> 4
759
+ #
760
+ # b = Thread.new { raise 'something went wrong' }
761
+ # b.value #=> RuntimeError: something went wrong
762
+ #
763
+ def value: () -> untyped
764
+
765
+ # <!--
766
+ # rdoc-file=thread.c
767
+ # - thr.wakeup -> thr
768
+ # -->
769
+ # Marks a given thread as eligible for scheduling, however it may still remain
770
+ # blocked on I/O.
771
+ #
772
+ # <strong>Note:</strong> This does not invoke the scheduler, see #run for more
773
+ # information.
774
+ #
775
+ # c = Thread.new { Thread.stop; puts "hey!" }
776
+ # sleep 0.1 while c.status!='sleep'
777
+ # c.wakeup
778
+ # c.join
779
+ # #=> "hey!"
780
+ #
781
+ def wakeup: () -> Thread
782
+
783
+ # <!--
784
+ # rdoc-file=thread.c
785
+ # - Thread.abort_on_exception -> true or false
786
+ # -->
787
+ # Returns the status of the global ``abort on exception'' condition.
788
+ #
789
+ # The default is `false`.
790
+ #
791
+ # When set to `true`, if any thread is aborted by an exception, the raised
792
+ # exception will be re-raised in the main thread.
793
+ #
794
+ # Can also be specified by the global $DEBUG flag or command line option
795
+ # <code>-d</code>.
796
+ #
797
+ # See also ::abort_on_exception=.
798
+ #
799
+ # There is also an instance level method to set this for a specific thread, see
800
+ # #abort_on_exception.
801
+ #
802
+ def self.abort_on_exception: () -> untyped
803
+
804
+ # <!--
805
+ # rdoc-file=thread.c
806
+ # - Thread.abort_on_exception= boolean -> true or false
807
+ # -->
808
+ # When set to `true`, if any thread is aborted by an exception, the raised
809
+ # exception will be re-raised in the main thread. Returns the new state.
810
+ #
811
+ # Thread.abort_on_exception = true
812
+ # t1 = Thread.new do
813
+ # puts "In new thread"
814
+ # raise "Exception from thread"
815
+ # end
816
+ # sleep(1)
817
+ # puts "not reached"
818
+ #
819
+ # This will produce:
820
+ #
821
+ # In new thread
822
+ # prog.rb:4: Exception from thread (RuntimeError)
823
+ # from prog.rb:2:in `initialize'
824
+ # from prog.rb:2:in `new'
825
+ # from prog.rb:2
826
+ #
827
+ # See also ::abort_on_exception.
828
+ #
829
+ # There is also an instance level method to set this for a specific thread, see
830
+ # #abort_on_exception=.
831
+ #
832
+ def self.abort_on_exception=: (untyped abort_on_exception) -> untyped
833
+
834
+ # <!--
835
+ # rdoc-file=vm_backtrace.c
836
+ # - Thread.each_caller_location(...) { |loc| ... } -> nil
837
+ # -->
838
+ # Yields each frame of the current execution stack as a backtrace location
839
+ # object.
840
+ #
841
+ def self.each_caller_location: () { (Backtrace::Location) -> void } -> nil
842
+
843
+ # <!--
844
+ # rdoc-file=thread.c
845
+ # - Thread.exit -> thread
846
+ # -->
847
+ # Terminates the currently running thread and schedules another thread to be
848
+ # run.
849
+ #
850
+ # If this thread is already marked to be killed, ::exit returns the Thread.
851
+ #
852
+ # If this is the main thread, or the last thread, exit the process.
853
+ #
854
+ def self.exit: () -> untyped
855
+
856
+ # <!--
857
+ # rdoc-file=thread.c
858
+ # - Thread.start([args]*) {|args| block } -> thread
859
+ # - Thread.fork([args]*) {|args| block } -> thread
860
+ # -->
861
+ # Basically the same as ::new. However, if class Thread is subclassed, then
862
+ # calling `start` in that subclass will not invoke the subclass's `initialize`
863
+ # method.
864
+ #
865
+ def self.fork: (*untyped args) -> untyped
866
+
867
+ # <!--
868
+ # rdoc-file=thread.c
869
+ # - Thread.handle_interrupt(hash) { ... } -> result of the block
870
+ # -->
871
+ # Changes asynchronous interrupt timing.
872
+ #
873
+ # *interrupt* means asynchronous event and corresponding procedure by
874
+ # Thread#raise, Thread#kill, signal trap (not supported yet) and main thread
875
+ # termination (if main thread terminates, then all other thread will be killed).
876
+ #
877
+ # The given `hash` has pairs like <code>ExceptionClass => :TimingSymbol</code>.
878
+ # Where the ExceptionClass is the interrupt handled by the given block. The
879
+ # TimingSymbol can be one of the following symbols:
880
+ #
881
+ # <code>:immediate</code>
882
+ # : Invoke interrupts immediately.
883
+ #
884
+ # <code>:on_blocking</code>
885
+ # : Invoke interrupts while *BlockingOperation*.
886
+ #
887
+ # <code>:never</code>
888
+ # : Never invoke all interrupts.
889
+ #
890
+ #
891
+ # *BlockingOperation* means that the operation will block the calling thread,
892
+ # such as read and write. On CRuby implementation, *BlockingOperation* is any
893
+ # operation executed without GVL.
894
+ #
895
+ # Masked asynchronous interrupts are delayed until they are enabled. This method
896
+ # is similar to sigprocmask(3).
897
+ #
898
+ # ### NOTE
899
+ #
900
+ # Asynchronous interrupts are difficult to use.
901
+ #
902
+ # If you need to communicate between threads, please consider to use another way
903
+ # such as Queue.
904
+ #
905
+ # Or use them with deep understanding about this method.
906
+ #
907
+ # ### Usage
908
+ #
909
+ # In this example, we can guard from Thread#raise exceptions.
910
+ #
911
+ # Using the <code>:never</code> TimingSymbol the RuntimeError exception will
912
+ # always be ignored in the first block of the main thread. In the second
913
+ # ::handle_interrupt block we can purposefully handle RuntimeError exceptions.
914
+ #
915
+ # th = Thread.new do
916
+ # Thread.handle_interrupt(RuntimeError => :never) {
917
+ # begin
918
+ # # You can write resource allocation code safely.
919
+ # Thread.handle_interrupt(RuntimeError => :immediate) {
920
+ # # ...
921
+ # }
922
+ # ensure
923
+ # # You can write resource deallocation code safely.
924
+ # end
925
+ # }
926
+ # end
927
+ # Thread.pass
928
+ # # ...
929
+ # th.raise "stop"
930
+ #
931
+ # While we are ignoring the RuntimeError exception, it's safe to write our
932
+ # resource allocation code. Then, the ensure block is where we can safely
933
+ # deallocate your resources.
934
+ #
935
+ # #### Stack control settings
936
+ #
937
+ # It's possible to stack multiple levels of ::handle_interrupt blocks in order
938
+ # to control more than one ExceptionClass and TimingSymbol at a time.
939
+ #
940
+ # Thread.handle_interrupt(FooError => :never) {
941
+ # Thread.handle_interrupt(BarError => :never) {
942
+ # # FooError and BarError are prohibited.
943
+ # }
944
+ # }
945
+ #
946
+ # #### Inheritance with ExceptionClass
947
+ #
948
+ # All exceptions inherited from the ExceptionClass parameter will be considered.
949
+ #
950
+ # Thread.handle_interrupt(Exception => :never) {
951
+ # # all exceptions inherited from Exception are prohibited.
952
+ # }
953
+ #
954
+ # For handling all interrupts, use `Object` and not `Exception` as the
955
+ # ExceptionClass, as kill/terminate interrupts are not handled by `Exception`.
956
+ #
957
+ def self.handle_interrupt: (untyped hash) -> untyped
958
+
959
+ # <!--
960
+ # rdoc-file=thread.c
961
+ # - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
962
+ # - raise(message = nil, cause: $!)
963
+ # -->
964
+ # Raises an exception from the given thread. The caller does not have to be
965
+ # `thr`. See Kernel#raise for more information on arguments.
966
+ #
967
+ # Thread.abort_on_exception = true
968
+ # a = Thread.new { sleep(200) }
969
+ # a.raise("Gotcha")
970
+ #
971
+ # This will produce:
972
+ #
973
+ # prog.rb:3: Gotcha (RuntimeError)
974
+ # from prog.rb:2:in `initialize'
975
+ # from prog.rb:2:in `new'
976
+ # from prog.rb:2
977
+ #
978
+ def raise: (?String message, ?cause: Exception?) -> nil
979
+ | (_Exception, ?_ToS message, ?Array[Thread::Backtrace::Location] | Array[String] | nil backtrace, ?cause: Exception?) -> nil
980
+
981
+ # <!--
982
+ # rdoc-file=thread.c
983
+ # - Thread.kill(thread) -> thread
984
+ # -->
985
+ # Causes the given `thread` to exit, see also Thread::exit.
986
+ #
987
+ # count = 0
988
+ # a = Thread.new { loop { count += 1 } }
989
+ # sleep(0.1) #=> 0
990
+ # Thread.kill(a) #=> #<Thread:0x401b3d30 dead>
991
+ # count #=> 93947
992
+ # a.alive? #=> false
993
+ #
994
+ def self.kill: (Thread thread) -> untyped
995
+
996
+ # <!--
997
+ # rdoc-file=thread.c
998
+ # - Thread.list -> array
999
+ # -->
1000
+ # Returns an array of Thread objects for all threads that are either runnable or
1001
+ # stopped.
1002
+ #
1003
+ # Thread.new { sleep(200) }
1004
+ # Thread.new { 1000000.times {|i| i*i } }
1005
+ # Thread.new { Thread.stop }
1006
+ # Thread.list.each {|t| p t}
1007
+ #
1008
+ # This will produce:
1009
+ #
1010
+ # #<Thread:0x401b3e84 sleep>
1011
+ # #<Thread:0x401b3f38 run>
1012
+ # #<Thread:0x401b3fb0 sleep>
1013
+ # #<Thread:0x401bdf4c run>
1014
+ #
1015
+ def self.list: () -> untyped
1016
+
1017
+ # <!--
1018
+ # rdoc-file=thread.c
1019
+ # - Thread.pass -> nil
1020
+ # -->
1021
+ # Give the thread scheduler a hint to pass execution to another thread. A
1022
+ # running thread may or may not switch, it depends on OS and processor.
1023
+ #
1024
+ def self.pass: () -> untyped
1025
+
1026
+ # <!--
1027
+ # rdoc-file=thread.c
1028
+ # - Thread.pending_interrupt?(error = nil) -> true/false
1029
+ # -->
1030
+ # Returns whether or not the asynchronous queue is empty.
1031
+ #
1032
+ # Since Thread::handle_interrupt can be used to defer asynchronous events, this
1033
+ # method can be used to determine if there are any deferred events.
1034
+ #
1035
+ # If you find this method returns true, then you may finish <code>:never</code>
1036
+ # blocks.
1037
+ #
1038
+ # For example, the following method processes deferred asynchronous events
1039
+ # immediately.
1040
+ #
1041
+ # def Thread.kick_interrupt_immediately
1042
+ # Thread.handle_interrupt(Object => :immediate) {
1043
+ # Thread.pass
1044
+ # }
1045
+ # end
1046
+ #
1047
+ # If `error` is given, then check only for `error` type deferred events.
1048
+ #
1049
+ # ### Usage
1050
+ #
1051
+ # th = Thread.new{
1052
+ # Thread.handle_interrupt(RuntimeError => :on_blocking){
1053
+ # while true
1054
+ # ...
1055
+ # # reach safe point to invoke interrupt
1056
+ # if Thread.pending_interrupt?
1057
+ # Thread.handle_interrupt(Object => :immediate){}
1058
+ # end
1059
+ # ...
1060
+ # end
1061
+ # }
1062
+ # }
1063
+ # ...
1064
+ # th.raise # stop thread
1065
+ #
1066
+ # This example can also be written as the following, which you should use to
1067
+ # avoid asynchronous interrupts.
1068
+ #
1069
+ # flag = true
1070
+ # th = Thread.new{
1071
+ # Thread.handle_interrupt(RuntimeError => :on_blocking){
1072
+ # while true
1073
+ # ...
1074
+ # # reach safe point to invoke interrupt
1075
+ # break if flag == false
1076
+ # ...
1077
+ # end
1078
+ # }
1079
+ # }
1080
+ # ...
1081
+ # flag = false # stop thread
1082
+ #
1083
+ def self.pending_interrupt?: (*untyped args) -> bool
1084
+
1085
+ # <!--
1086
+ # rdoc-file=thread.c
1087
+ # - Thread.report_on_exception -> true or false
1088
+ # -->
1089
+ # Returns the status of the global ``report on exception'' condition.
1090
+ #
1091
+ # The default is `true` since Ruby 2.5.
1092
+ #
1093
+ # All threads created when this flag is true will report a message on $stderr if
1094
+ # an exception kills the thread.
1095
+ #
1096
+ # Thread.new { 1.times { raise } }
1097
+ #
1098
+ # will produce this output on $stderr:
1099
+ #
1100
+ # #<Thread:...> terminated with exception (report_on_exception is true):
1101
+ # Traceback (most recent call last):
1102
+ # 2: from -e:1:in `block in <main>'
1103
+ # 1: from -e:1:in `times'
1104
+ #
1105
+ # This is done to catch errors in threads early. In some cases, you might not
1106
+ # want this output. There are multiple ways to avoid the extra output:
1107
+ #
1108
+ # * If the exception is not intended, the best is to fix the cause of the
1109
+ # exception so it does not happen anymore.
1110
+ # * If the exception is intended, it might be better to rescue it closer to
1111
+ # where it is raised rather then let it kill the Thread.
1112
+ # * If it is guaranteed the Thread will be joined with Thread#join or
1113
+ # Thread#value, then it is safe to disable this report with
1114
+ # <code>Thread.current.report_on_exception = false</code> when starting the
1115
+ # Thread. However, this might handle the exception much later, or not at all
1116
+ # if the Thread is never joined due to the parent thread being blocked, etc.
1117
+ #
1118
+ # See also ::report_on_exception=.
1119
+ #
1120
+ # There is also an instance level method to set this for a specific thread, see
1121
+ # #report_on_exception=.
1122
+ #
1123
+ def self.report_on_exception: () -> untyped
1124
+
1125
+ # <!--
1126
+ # rdoc-file=thread.c
1127
+ # - Thread.report_on_exception= boolean -> true or false
1128
+ # -->
1129
+ # Returns the new state. When set to `true`, all threads created afterwards will
1130
+ # inherit the condition and report a message on $stderr if an exception kills a
1131
+ # thread:
1132
+ #
1133
+ # Thread.report_on_exception = true
1134
+ # t1 = Thread.new do
1135
+ # puts "In new thread"
1136
+ # raise "Exception from thread"
1137
+ # end
1138
+ # sleep(1)
1139
+ # puts "In the main thread"
1140
+ #
1141
+ # This will produce:
1142
+ #
1143
+ # In new thread
1144
+ # #<Thread:...prog.rb:2> terminated with exception (report_on_exception is true):
1145
+ # Traceback (most recent call last):
1146
+ # prog.rb:4:in `block in <main>': Exception from thread (RuntimeError)
1147
+ # In the main thread
1148
+ #
1149
+ # See also ::report_on_exception.
1150
+ #
1151
+ # There is also an instance level method to set this for a specific thread, see
1152
+ # #report_on_exception=.
1153
+ #
1154
+ def self.report_on_exception=: (untyped report_on_exception) -> untyped
1155
+
1156
+ # <!--
1157
+ # rdoc-file=thread.c
1158
+ # - Thread.start([args]*) {|args| block } -> thread
1159
+ # - Thread.fork([args]*) {|args| block } -> thread
1160
+ # -->
1161
+ # Basically the same as ::new. However, if class Thread is subclassed, then
1162
+ # calling `start` in that subclass will not invoke the subclass's `initialize`
1163
+ # method.
1164
+ #
1165
+ def self.start: (*untyped args) { (?) -> void } -> instance
1166
+
1167
+ # <!--
1168
+ # rdoc-file=thread.c
1169
+ # - Thread.stop -> nil
1170
+ # -->
1171
+ # Stops execution of the current thread, putting it into a ``sleep'' state, and
1172
+ # schedules execution of another thread.
1173
+ #
1174
+ # a = Thread.new { print "a"; Thread.stop; print "c" }
1175
+ # sleep 0.1 while a.status!='sleep'
1176
+ # print "b"
1177
+ # a.run
1178
+ # a.join
1179
+ # #=> "abc"
1180
+ #
1181
+ def self.stop: () -> untyped
1182
+ end
1183
+
1184
+ # <!-- rdoc-file=vm_backtrace.c -->
1185
+ # An internal representation of the backtrace. The user will never interact with
1186
+ # objects of this class directly, but class methods can be used to get backtrace
1187
+ # settings of the current session.
1188
+ #
1189
+ class Thread::Backtrace < Object
1190
+ # <!--
1191
+ # rdoc-file=vm_backtrace.c
1192
+ # - Thread::Backtrace::limit -> integer
1193
+ # -->
1194
+ # Returns maximum backtrace length set by <code>--backtrace-limit</code>
1195
+ # command-line option. The default is <code>-1</code> which means unlimited
1196
+ # backtraces. If the value is zero or positive, the error backtraces, produced
1197
+ # by Exception#full_message, are abbreviated and the extra lines are replaced by
1198
+ # <code>... 3 levels... </code>
1199
+ #
1200
+ # $ ruby -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
1201
+ # - 1
1202
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
1203
+ # from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
1204
+ # from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
1205
+ # from .../lib/ruby/3.1.0/net/http.rb:998:in `connect'
1206
+ # from .../lib/ruby/3.1.0/net/http.rb:976:in `do_start'
1207
+ # from .../lib/ruby/3.1.0/net/http.rb:965:in `start'
1208
+ # from .../lib/ruby/3.1.0/net/http.rb:627:in `start'
1209
+ # from .../lib/ruby/3.1.0/net/http.rb:503:in `get_response'
1210
+ # from .../lib/ruby/3.1.0/net/http.rb:474:in `get'
1211
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
1212
+ # from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
1213
+ # from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
1214
+ # from .../lib/ruby/3.1.0/net/http.rb:998:in `connect'
1215
+ # from .../lib/ruby/3.1.0/net/http.rb:976:in `do_start'
1216
+ # from .../lib/ruby/3.1.0/net/http.rb:965:in `start'
1217
+ # from .../lib/ruby/3.1.0/net/http.rb:627:in `start'
1218
+ # from .../lib/ruby/3.1.0/net/http.rb:503:in `get_response'
1219
+ # from .../lib/ruby/3.1.0/net/http.rb:474:in `get'
1220
+ # from -e:1:in `<main>'
1221
+ #
1222
+ # $ ruby --backtrace-limit 2 -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
1223
+ # 2
1224
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
1225
+ # from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
1226
+ # from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
1227
+ # ... 7 levels...
1228
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
1229
+ # from .../lib/ruby/3.1.0/socket.rb:227:in `foreach'
1230
+ # from .../lib/ruby/3.1.0/socket.rb:632:in `tcp'
1231
+ # ... 7 levels...
1232
+ #
1233
+ # $ ruby --backtrace-limit 0 -r net/http -e "p Thread::Backtrace.limit; Net::HTTP.get(URI('http://wrong.address'))"
1234
+ # 0
1235
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': Failed to open TCP connection to wrong.address:80 (getaddrinfo: Name or service not known) (SocketError)
1236
+ # ... 9 levels...
1237
+ # .../lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
1238
+ # ... 9 levels...
1239
+ #
1240
+ def self.limit: () -> Integer
1241
+ end
1242
+
1243
+ # <!-- rdoc-file=vm_backtrace.c -->
1244
+ # An object representation of a stack frame, initialized by
1245
+ # Kernel#caller_locations.
1246
+ #
1247
+ # For example:
1248
+ #
1249
+ # # caller_locations.rb
1250
+ # def a(skip)
1251
+ # caller_locations(skip)
1252
+ # end
1253
+ # def b(skip)
1254
+ # a(skip)
1255
+ # end
1256
+ # def c(skip)
1257
+ # b(skip)
1258
+ # end
1259
+ #
1260
+ # c(0..2).map do |call|
1261
+ # puts call.to_s
1262
+ # end
1263
+ #
1264
+ # Running <code>ruby caller_locations.rb</code> will produce:
1265
+ #
1266
+ # caller_locations.rb:2:in `a'
1267
+ # caller_locations.rb:5:in `b'
1268
+ # caller_locations.rb:8:in `c'
1269
+ #
1270
+ # Here's another example with a slightly different result:
1271
+ #
1272
+ # # foo.rb
1273
+ # class Foo
1274
+ # attr_accessor :locations
1275
+ # def initialize(skip)
1276
+ # @locations = caller_locations(skip)
1277
+ # end
1278
+ # end
1279
+ #
1280
+ # Foo.new(0..2).locations.map do |call|
1281
+ # puts call.to_s
1282
+ # end
1283
+ #
1284
+ # Now run <code>ruby foo.rb</code> and you should see:
1285
+ #
1286
+ # init.rb:4:in `initialize'
1287
+ # init.rb:8:in `new'
1288
+ # init.rb:8:in `<main>'
1289
+ #
1290
+ class Thread::Backtrace::Location
1291
+ # <!--
1292
+ # rdoc-file=vm_backtrace.c
1293
+ # - absolute_path()
1294
+ # -->
1295
+ # Returns the full file path of this frame.
1296
+ #
1297
+ # Same as #path, except that it will return absolute path even if the frame is
1298
+ # in the main script.
1299
+ #
1300
+ def absolute_path: () -> String?
1301
+
1302
+ # <!--
1303
+ # rdoc-file=vm_backtrace.c
1304
+ # - base_label()
1305
+ # -->
1306
+ # Returns the base label of this frame, which is usually equal to the label,
1307
+ # without decoration.
1308
+ #
1309
+ # Consider the following example:
1310
+ #
1311
+ # def foo
1312
+ # puts caller_locations(0).first.base_label
1313
+ #
1314
+ # 1.times do
1315
+ # puts caller_locations(0).first.base_label
1316
+ #
1317
+ # 1.times do
1318
+ # puts caller_locations(0).first.base_label
1319
+ # end
1320
+ # end
1321
+ # end
1322
+ #
1323
+ # The result of calling `foo` is this:
1324
+ #
1325
+ # foo
1326
+ # foo
1327
+ # foo
1328
+ #
1329
+ def base_label: () -> String?
1330
+
1331
+ # <!--
1332
+ # rdoc-file=vm_backtrace.c
1333
+ # - label()
1334
+ # -->
1335
+ # Returns the label of this frame.
1336
+ #
1337
+ # Usually consists of method, class, module, etc names with decoration.
1338
+ #
1339
+ # Consider the following example:
1340
+ #
1341
+ # def foo
1342
+ # puts caller_locations(0).first.label
1343
+ #
1344
+ # 1.times do
1345
+ # puts caller_locations(0).first.label
1346
+ #
1347
+ # 1.times do
1348
+ # puts caller_locations(0).first.label
1349
+ # end
1350
+ # end
1351
+ # end
1352
+ #
1353
+ # The result of calling `foo` is this:
1354
+ #
1355
+ # foo
1356
+ # block in foo
1357
+ # block (2 levels) in foo
1358
+ #
1359
+ def label: () -> String?
1360
+
1361
+ # <!--
1362
+ # rdoc-file=vm_backtrace.c
1363
+ # - lineno()
1364
+ # -->
1365
+ # Returns the line number of this frame.
1366
+ #
1367
+ # For example, using <code>caller_locations.rb</code> from
1368
+ # Thread::Backtrace::Location
1369
+ #
1370
+ # loc = c(0..1).first
1371
+ # loc.lineno #=> 2
1372
+ #
1373
+ def lineno: () -> Integer
1374
+
1375
+ # <!--
1376
+ # rdoc-file=vm_backtrace.c
1377
+ # - path()
1378
+ # -->
1379
+ # Returns the file name of this frame. This will generally be an absolute path,
1380
+ # unless the frame is in the main script, in which case it will be the script
1381
+ # location passed on the command line.
1382
+ #
1383
+ # For example, using <code>caller_locations.rb</code> from
1384
+ # Thread::Backtrace::Location
1385
+ #
1386
+ # loc = c(0..1).first
1387
+ # loc.path #=> caller_locations.rb
1388
+ #
1389
+ def path: () -> String?
1390
+ end
1391
+
1392
+ # <!-- rdoc-file=thread_sync.c -->
1393
+ # ConditionVariable objects augment class Mutex. Using condition variables, it
1394
+ # is possible to suspend while in the middle of a critical section until a
1395
+ # condition is met, such as a resource becomes available.
1396
+ #
1397
+ # Due to non-deterministic scheduling and spurious wake-ups, users of condition
1398
+ # variables should always use a separate boolean predicate (such as reading from
1399
+ # a boolean variable) to check if the condition is actually met before starting
1400
+ # to wait, and should wait in a loop, re-checking the condition every time the
1401
+ # ConditionVariable is waken up. The idiomatic way of using condition variables
1402
+ # is calling the `wait` method in an `until` loop with the predicate as the loop
1403
+ # condition.
1404
+ #
1405
+ # condvar.wait(mutex) until condition_is_met
1406
+ #
1407
+ # In the example below, we use the boolean variable `resource_available` (which
1408
+ # is protected by `mutex`) to indicate the availability of the resource, and use
1409
+ # `condvar` to wait for that variable to become true. Note that:
1410
+ #
1411
+ # 1. Thread `b` may be scheduled before thread `a1` and `a2`, and may run so
1412
+ # fast that it have already made the resource available before either `a1`
1413
+ # or `a2` starts. Therefore, `a1` and `a2` should check if
1414
+ # `resource_available` is already true before starting to wait.
1415
+ # 2. The `wait` method may spuriously wake up without signalling. Therefore,
1416
+ # thread `a1` and `a2` should recheck `resource_available` after the `wait`
1417
+ # method returns, and go back to wait if the condition is not actually met.
1418
+ # 3. It is possible that thread `a2` starts right after thread `a1` is waken up
1419
+ # by `b`. Thread `a2` may have acquired the `mutex` and consumed the
1420
+ # resource before thread `a1` acquires the `mutex`. This necessitates
1421
+ # rechecking after `wait`, too.
1422
+ #
1423
+ # Example:
1424
+ #
1425
+ # mutex = Thread::Mutex.new
1426
+ #
1427
+ # resource_available = false
1428
+ # condvar = Thread::ConditionVariable.new
1429
+ #
1430
+ # a1 = Thread.new {
1431
+ # # Thread 'a1' waits for the resource to become available and consumes
1432
+ # # the resource.
1433
+ # mutex.synchronize {
1434
+ # condvar.wait(mutex) until resource_available
1435
+ # # After the loop, 'resource_available' is guaranteed to be true.
1436
+ #
1437
+ # resource_available = false
1438
+ # puts "a1 consumed the resource"
1439
+ # }
1440
+ # }
1441
+ #
1442
+ # a2 = Thread.new {
1443
+ # # Thread 'a2' behaves like 'a1'.
1444
+ # mutex.synchronize {
1445
+ # condvar.wait(mutex) until resource_available
1446
+ # resource_available = false
1447
+ # puts "a2 consumed the resource"
1448
+ # }
1449
+ # }
1450
+ #
1451
+ # b = Thread.new {
1452
+ # # Thread 'b' periodically makes the resource available.
1453
+ # loop {
1454
+ # mutex.synchronize {
1455
+ # resource_available = true
1456
+ #
1457
+ # # Notify one waiting thread if any. It is possible that neither
1458
+ # # 'a1' nor 'a2 is waiting on 'condvar' at this moment. That's OK.
1459
+ # condvar.signal
1460
+ # }
1461
+ # sleep 1
1462
+ # }
1463
+ # }
1464
+ #
1465
+ # # Eventually both 'a1' and 'a2' will have their resources, albeit in an
1466
+ # # unspecified order.
1467
+ # [a1, a2].each {|th| th.join}
1468
+ #
1469
+ class Thread::ConditionVariable < Object
1470
+ # <!--
1471
+ # rdoc-file=thread_sync.c
1472
+ # - broadcast()
1473
+ # -->
1474
+ # Wakes up all threads waiting for this lock.
1475
+ #
1476
+ def broadcast: () -> self
1477
+
1478
+ # <!--
1479
+ # rdoc-file=thread_sync.c
1480
+ # - signal()
1481
+ # -->
1482
+ # Wakes up the first thread in line waiting for this lock.
1483
+ #
1484
+ def signal: () -> self
1485
+
1486
+ # <!--
1487
+ # rdoc-file=thread_sync.c
1488
+ # - wait(mutex, timeout=nil)
1489
+ # -->
1490
+ # Releases the lock held in `mutex` and waits; reacquires the lock on wakeup.
1491
+ #
1492
+ # If `timeout` is given, this method returns after `timeout` seconds passed,
1493
+ # even if no other thread doesn't signal.
1494
+ #
1495
+ # This method may wake up spuriously due to underlying implementation details.
1496
+ #
1497
+ # Returns the slept result on `mutex`.
1498
+ #
1499
+ def wait: (Thread::Mutex mutex, ?Time::_Timeout? timeout) -> Integer?
1500
+ end
1501
+
1502
+ # <!-- rdoc-file=thread_sync.c -->
1503
+ # Thread::Mutex implements a simple semaphore that can be used to coordinate
1504
+ # access to shared data from multiple concurrent threads.
1505
+ #
1506
+ # Example:
1507
+ #
1508
+ # semaphore = Thread::Mutex.new
1509
+ #
1510
+ # a = Thread.new {
1511
+ # semaphore.synchronize {
1512
+ # # access shared resource
1513
+ # }
1514
+ # }
1515
+ #
1516
+ # b = Thread.new {
1517
+ # semaphore.synchronize {
1518
+ # # access shared resource
1519
+ # }
1520
+ # }
1521
+ #
1522
+ class Thread::Mutex < Object
1523
+ # <!--
1524
+ # rdoc-file=thread_sync.rb
1525
+ # - mutex.lock -> self
1526
+ # -->
1527
+ # Attempts to grab the lock and waits if it isn't available. Raises
1528
+ # `ThreadError` if `mutex` was locked by the current thread.
1529
+ #
1530
+ def lock: () -> self
1531
+
1532
+ # <!--
1533
+ # rdoc-file=thread_sync.rb
1534
+ # - mutex.locked? -> true or false
1535
+ # -->
1536
+ # Returns `true` if this lock is currently held by some thread.
1537
+ #
1538
+ def locked?: () -> bool
1539
+
1540
+ # <!--
1541
+ # rdoc-file=thread_sync.rb
1542
+ # - mutex.owned? -> true or false
1543
+ # -->
1544
+ # Returns `true` if this lock is currently held by current thread.
1545
+ #
1546
+ def owned?: () -> bool
1547
+
1548
+ # <!--
1549
+ # rdoc-file=thread_sync.rb
1550
+ # - mutex.synchronize { ... } -> result of the block
1551
+ # -->
1552
+ # Obtains a lock, runs the block, and releases the lock when the block
1553
+ # completes. See the example under Thread::Mutex.
1554
+ #
1555
+ def synchronize: [X] () { () -> X } -> X
1556
+
1557
+ # <!--
1558
+ # rdoc-file=thread_sync.rb
1559
+ # - mutex.try_lock -> true or false
1560
+ # -->
1561
+ # Attempts to obtain the lock and returns immediately. Returns `true` if the
1562
+ # lock was granted.
1563
+ #
1564
+ def try_lock: () -> bool
1565
+
1566
+ # <!--
1567
+ # rdoc-file=thread_sync.rb
1568
+ # - mutex.lock -> self
1569
+ # -->
1570
+ # Attempts to grab the lock and waits if it isn't available. Raises
1571
+ # `ThreadError` if `mutex` was locked by the current thread.
1572
+ #
1573
+ def unlock: () -> self
1574
+ end
1575
+
1576
+ # <!-- rdoc-file=thread_sync.c -->
1577
+ # The Thread::Queue class implements multi-producer, multi-consumer queues. It
1578
+ # is especially useful in threaded programming when information must be
1579
+ # exchanged safely between multiple threads. The Thread::Queue class implements
1580
+ # all the required locking semantics.
1581
+ #
1582
+ # The class implements FIFO (first in, first out) type of queue. In a FIFO
1583
+ # queue, the first tasks added are the first retrieved.
1584
+ #
1585
+ # Example:
1586
+ #
1587
+ # queue = Thread::Queue.new
1588
+ #
1589
+ # producer = Thread.new do
1590
+ # 5.times do |i|
1591
+ # sleep rand(i) # simulate expense
1592
+ # queue << i
1593
+ # puts "#{i} produced"
1594
+ # end
1595
+ # end
1596
+ #
1597
+ # consumer = Thread.new do
1598
+ # 5.times do |i|
1599
+ # value = queue.pop
1600
+ # sleep rand(i/2) # simulate expense
1601
+ # puts "consumed #{value}"
1602
+ # end
1603
+ # end
1604
+ #
1605
+ # consumer.join
1606
+ #
1607
+ class Thread::Queue[E = untyped] < Object
1608
+ # <!-- rdoc-file=thread_sync.c -->
1609
+ # Pushes the given `object` to the queue.
1610
+ #
1611
+ alias << push
1612
+
1613
+ # <!--
1614
+ # rdoc-file=thread_sync.c
1615
+ # - clear()
1616
+ # -->
1617
+ # Removes all objects from the queue.
1618
+ #
1619
+ def clear: () -> void
1620
+
1621
+ # <!--
1622
+ # rdoc-file=thread_sync.c
1623
+ # - close
1624
+ # -->
1625
+ # Closes the queue. A closed queue cannot be re-opened.
1626
+ #
1627
+ # After the call to close completes, the following are true:
1628
+ #
1629
+ # * <code>closed?</code> will return true
1630
+ #
1631
+ # * `close` will be ignored.
1632
+ #
1633
+ # * calling enq/push/<< will raise a `ClosedQueueError`.
1634
+ #
1635
+ # * when <code>empty?</code> is false, calling deq/pop/shift will return an
1636
+ # object from the queue as usual.
1637
+ # * when <code>empty?</code> is true, deq(false) will not suspend the thread
1638
+ # and will return nil. deq(true) will raise a `ThreadError`.
1639
+ #
1640
+ # ClosedQueueError is inherited from StopIteration, so that you can break loop
1641
+ # block.
1642
+ #
1643
+ # Example:
1644
+ #
1645
+ # q = Thread::Queue.new
1646
+ # Thread.new{
1647
+ # while e = q.deq # wait for nil to break loop
1648
+ # # ...
1649
+ # end
1650
+ # }
1651
+ # q.close
1652
+ #
1653
+ def close: () -> self
1654
+
1655
+ # <!--
1656
+ # rdoc-file=thread_sync.c
1657
+ # - closed?
1658
+ # -->
1659
+ # Returns `true` if the queue is closed.
1660
+ #
1661
+ def closed?: () -> bool
1662
+
1663
+ # <!--
1664
+ # rdoc-file=thread_sync.rb
1665
+ # - deq(non_block = false, timeout: nil)
1666
+ # -->
1667
+ #
1668
+ alias deq pop
1669
+
1670
+ # <!--
1671
+ # rdoc-file=thread_sync.c
1672
+ # - empty?
1673
+ # -->
1674
+ # Returns `true` if the queue is empty.
1675
+ #
1676
+ def empty?: () -> bool
1677
+
1678
+ # <!-- rdoc-file=thread_sync.c -->
1679
+ # Pushes the given `object` to the queue.
1680
+ #
1681
+ alias enq push
1682
+
1683
+ # <!--
1684
+ # rdoc-file=thread_sync.c
1685
+ # - freeze
1686
+ # -->
1687
+ # The queue can't be frozen, so this method raises an exception:
1688
+ # Thread::Queue.new.freeze # Raises TypeError (cannot freeze #<Thread::Queue:0x...>)
1689
+ #
1690
+ def freeze: () -> bot
1691
+
1692
+ # <!--
1693
+ # rdoc-file=thread_sync.c
1694
+ # - length
1695
+ # - size
1696
+ # -->
1697
+ # Returns the length of the queue.
1698
+ #
1699
+ def length: () -> Integer
1700
+
1701
+ # <!--
1702
+ # rdoc-file=thread_sync.c
1703
+ # - num_waiting()
1704
+ # -->
1705
+ # Returns the number of threads waiting on the queue.
1706
+ #
1707
+ def num_waiting: () -> Integer
1708
+
1709
+ # <!--
1710
+ # rdoc-file=thread_sync.rb
1711
+ # - pop(non_block=false, timeout: nil)
1712
+ # -->
1713
+ # Retrieves data from the queue.
1714
+ #
1715
+ # If the queue is empty, the calling thread is suspended until data is pushed
1716
+ # onto the queue. If `non_block` is true, the thread isn't suspended, and
1717
+ # `ThreadError` is raised.
1718
+ #
1719
+ # If `timeout` seconds have passed and no data is available `nil` is returned.
1720
+ # If `timeout` is `0` it returns immediately.
1721
+ #
1722
+ def pop: (?boolish non_block, ?timeout: _ToF?) -> E?
1723
+
1724
+ # <!--
1725
+ # rdoc-file=thread_sync.c
1726
+ # - push(object)
1727
+ # - enq(object)
1728
+ # - <<(object)
1729
+ # -->
1730
+ # Pushes the given `object` to the queue.
1731
+ #
1732
+ def push: (E obj) -> void
1733
+
1734
+ # <!--
1735
+ # rdoc-file=thread_sync.rb
1736
+ # - shift(non_block = false, timeout: nil)
1737
+ # -->
1738
+ #
1739
+ alias shift pop
1740
+
1741
+ # <!-- rdoc-file=thread_sync.c -->
1742
+ # Returns the length of the queue.
1743
+ #
1744
+ alias size length
1745
+ end
1746
+
1747
+ # <!-- rdoc-file=thread_sync.c -->
1748
+ # This class represents queues of specified size capacity. The push operation
1749
+ # may be blocked if the capacity is full.
1750
+ #
1751
+ # See Thread::Queue for an example of how a Thread::SizedQueue works.
1752
+ #
1753
+ class Thread::SizedQueue[E = untyped] < Thread::Queue[E]
1754
+ # <!--
1755
+ # rdoc-file=thread_sync.rb
1756
+ # - <<(object, non_block = false, timeout: nil)
1757
+ # -->
1758
+ #
1759
+ alias << push
1760
+
1761
+ # <!--
1762
+ # rdoc-file=thread_sync.rb
1763
+ # - enq(object, non_block = false, timeout: nil)
1764
+ # -->
1765
+ #
1766
+ alias enq push
1767
+
1768
+ # <!--
1769
+ # rdoc-file=thread_sync.c
1770
+ # - freeze
1771
+ # -->
1772
+ # The queue can't be frozen, so this method raises an exception:
1773
+ # Thread::Queue.new.freeze # Raises TypeError (cannot freeze #<Thread::Queue:0x...>)
1774
+ #
1775
+ def freeze: () -> bot
1776
+
1777
+ # <!--
1778
+ # rdoc-file=thread_sync.c
1779
+ # - new(max)
1780
+ # -->
1781
+ # Creates a fixed-length queue with a maximum size of `max`.
1782
+ #
1783
+ def initialize: (Integer max) -> void
1784
+
1785
+ # <!--
1786
+ # rdoc-file=thread_sync.c
1787
+ # - max()
1788
+ # -->
1789
+ # Returns the maximum size of the queue.
1790
+ #
1791
+ def max: () -> Integer
1792
+
1793
+ # <!--
1794
+ # rdoc-file=thread_sync.c
1795
+ # - max=(number)
1796
+ # -->
1797
+ # Sets the maximum size of the queue to the given `number`.
1798
+ #
1799
+ def max=: (Integer max) -> void
1800
+
1801
+ # <!--
1802
+ # rdoc-file=thread_sync.rb
1803
+ # - push(object, non_block=false, timeout: nil)
1804
+ # - enq(object, non_block=false, timeout: nil)
1805
+ # - <<(object)
1806
+ # -->
1807
+ # Pushes `object` to the queue.
1808
+ #
1809
+ # If there is no space left in the queue, waits until space becomes available,
1810
+ # unless `non_block` is true. If `non_block` is true, the thread isn't
1811
+ # suspended, and `ThreadError` is raised.
1812
+ #
1813
+ # If `timeout` seconds have passed and no space is available `nil` is returned.
1814
+ # If `timeout` is `0` it returns immediately. Otherwise it returns `self`.
1815
+ #
1816
+ def push: (E obj, ?boolish non_block) -> void
1817
+ | (E obj, timeout: _ToF?) -> self?
1818
+ end
1819
+
1820
+ class ConditionVariable = Thread::ConditionVariable
1821
+
1822
+ class Mutex = Thread::Mutex
1823
+
1824
+ class Queue = Thread::Queue
1825
+
1826
+ class SizedQueue = Thread::SizedQueue