steep 0.14.0 → 0.16.3
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.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +25 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +18 -2
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +55 -55
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +13 -457
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +9 -13
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +43 -46
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +996 -726
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +79 -22
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +7 -8
- metadata +26 -141
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -67
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1344
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1894
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,13 +0,0 @@
|
|
1
|
-
class StringIO
|
2
|
-
def initialize: (?String, ?String) -> untyped
|
3
|
-
def puts: (*untyped) -> void
|
4
|
-
def readline: () -> String
|
5
|
-
| (String) -> String
|
6
|
-
def write: (String) -> void
|
7
|
-
def flush: () -> void
|
8
|
-
def string: -> String
|
9
|
-
def close_read: -> nil
|
10
|
-
def closed_read?: -> bool
|
11
|
-
def close_write: -> nil
|
12
|
-
def closed_write?: -> bool
|
13
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# A [Struct](Struct) is a convenient way to bundle a
|
2
|
-
# number of attributes together, using accessor methods, without having to
|
3
|
-
# write an explicit class.
|
4
|
-
#
|
5
|
-
# The [Struct](Struct) class generates new subclasses
|
6
|
-
# that hold a set of members and their values. For each member a reader
|
7
|
-
# and writer method is created similar to
|
8
|
-
# [Module\#attr\_accessor](https://ruby-doc.org/core-2.6.3/Module.html#method-i-attr_accessor)
|
9
|
-
# .
|
10
|
-
#
|
11
|
-
# ```ruby
|
12
|
-
# Customer = Struct.new(:name, :address) do
|
13
|
-
# def greeting
|
14
|
-
# "Hello #{name}!"
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# dave = Customer.new("Dave", "123 Main")
|
19
|
-
# dave.name #=> "Dave"
|
20
|
-
# dave.greeting #=> "Hello Dave!"
|
21
|
-
# ```
|
22
|
-
#
|
23
|
-
# See [::new](Struct#method-c-new) for further
|
24
|
-
# examples of creating struct subclasses and instances.
|
25
|
-
#
|
26
|
-
# In the method descriptions that follow, a "member" parameter refers to a
|
27
|
-
# struct member which is either a quoted string ( `"name"` ) or a
|
28
|
-
# [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
|
29
|
-
class Struct[Elem] < Object
|
30
|
-
include Enumerable[Elem, Struct[Elem]]
|
31
|
-
|
32
|
-
def initialize: (Symbol | String arg0, *Symbol | String arg1, ?keyword_init: bool keyword_init) -> void
|
33
|
-
|
34
|
-
def each: () { (Elem arg0) -> untyped } -> untyped
|
35
|
-
| () -> self
|
36
|
-
|
37
|
-
def self.members: () -> ::Array[Symbol]
|
38
|
-
|
39
|
-
def new: (*untyped args) -> Struct[untyped]
|
40
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
# Symbol objects represent names inside the Ruby interpreter. They are generated
|
2
|
-
# using the `:name` and `:"string"` literals syntax, and by the various `to_sym`
|
3
|
-
# methods. The same Symbol object will be created for a given name or string for
|
4
|
-
# the duration of a program's execution, regardless of the context or meaning of
|
5
|
-
# that name. Thus if `Fred` is a constant in one context, a method in another,
|
6
|
-
# and a class in a third, the Symbol `:Fred` will be the same object in all
|
7
|
-
# three contexts.
|
8
|
-
#
|
9
|
-
# module One
|
10
|
-
# class Fred
|
11
|
-
# end
|
12
|
-
# $f1 = :Fred
|
13
|
-
# end
|
14
|
-
# module Two
|
15
|
-
# Fred = 1
|
16
|
-
# $f2 = :Fred
|
17
|
-
# end
|
18
|
-
# def Fred()
|
19
|
-
# end
|
20
|
-
# $f3 = :Fred
|
21
|
-
# $f1.object_id #=> 2514190
|
22
|
-
# $f2.object_id #=> 2514190
|
23
|
-
# $f3.object_id #=> 2514190
|
24
|
-
#
|
25
|
-
class Symbol
|
26
|
-
include Comparable
|
27
|
-
|
28
|
-
# Returns an array of all the symbols currently in Ruby's symbol table.
|
29
|
-
#
|
30
|
-
# Symbol.all_symbols.size #=> 903
|
31
|
-
# Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink,
|
32
|
-
# :chown, :EOFError, :$;, :String,
|
33
|
-
# :LOCK_SH, :"setuid?", :$<,
|
34
|
-
# :default_proc, :compact, :extend,
|
35
|
-
# :Tms, :getwd, :$=, :ThreadGroup,
|
36
|
-
# :wait2, :$>]
|
37
|
-
#
|
38
|
-
def self.all_symbols: () -> ::Array[Symbol]
|
39
|
-
|
40
|
-
public
|
41
|
-
|
42
|
-
# Compares `symbol` with `other_symbol` after calling #to_s on each of the
|
43
|
-
# symbols. Returns -1, 0, +1, or `nil` depending on whether `symbol` is less
|
44
|
-
# than, equal to, or greater than `other_symbol`.
|
45
|
-
#
|
46
|
-
# `nil` is returned if the two values are incomparable.
|
47
|
-
#
|
48
|
-
# See String#<=> for more information.
|
49
|
-
#
|
50
|
-
def <=>: (Symbol other) -> Integer
|
51
|
-
| (untyped other) -> Integer?
|
52
|
-
|
53
|
-
# Equality---If *sym* and *obj* are exactly the same symbol, returns `true`.
|
54
|
-
#
|
55
|
-
def ==: (untyped obj) -> bool
|
56
|
-
|
57
|
-
# Equality---If *sym* and *obj* are exactly the same symbol, returns `true`.
|
58
|
-
#
|
59
|
-
def ===: (untyped obj) -> bool
|
60
|
-
|
61
|
-
# Returns `sym.to_s =~ obj`.
|
62
|
-
#
|
63
|
-
def =~: (untyped obj) -> Integer?
|
64
|
-
|
65
|
-
# Returns `sym.to_s[]`.
|
66
|
-
#
|
67
|
-
def []: (Integer index) -> String?
|
68
|
-
| (Integer start, Integer length) -> String?
|
69
|
-
| (Range[Integer?] range) -> String?
|
70
|
-
| (Regexp regexp) -> String?
|
71
|
-
| (Regexp regexp, Integer | String capture) -> String?
|
72
|
-
| (String match_str) -> String?
|
73
|
-
|
74
|
-
# Same as `sym.to_s.capitalize.intern`.
|
75
|
-
#
|
76
|
-
def capitalize: () -> Symbol
|
77
|
-
| (:ascii | :lithuanian | :turkic) -> Symbol
|
78
|
-
| (:lithuanian, :turkic) -> Symbol
|
79
|
-
| (:turkic, :lithuanian) -> Symbol
|
80
|
-
|
81
|
-
# Case-insensitive version of Symbol#<=>. Currently, case-insensitivity only
|
82
|
-
# works on characters A-Z/a-z, not all of Unicode. This is different from
|
83
|
-
# Symbol#casecmp?.
|
84
|
-
#
|
85
|
-
# :aBcDeF.casecmp(:abcde) #=> 1
|
86
|
-
# :aBcDeF.casecmp(:abcdef) #=> 0
|
87
|
-
# :aBcDeF.casecmp(:abcdefg) #=> -1
|
88
|
-
# :abcdef.casecmp(:ABCDEF) #=> 0
|
89
|
-
#
|
90
|
-
# `nil` is returned if the two symbols have incompatible encodings, or if
|
91
|
-
# `other_symbol` is not a symbol.
|
92
|
-
#
|
93
|
-
# :foo.casecmp(2) #=> nil
|
94
|
-
# "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym.casecmp(:"\u{c4 d6 dc}") #=> nil
|
95
|
-
#
|
96
|
-
def casecmp: (Symbol other) -> Integer?
|
97
|
-
| (untyped other) -> Integer?
|
98
|
-
|
99
|
-
# Returns `true` if `sym` and `other_symbol` are equal after Unicode case
|
100
|
-
# folding, `false` if they are not equal.
|
101
|
-
#
|
102
|
-
# :aBcDeF.casecmp?(:abcde) #=> false
|
103
|
-
# :aBcDeF.casecmp?(:abcdef) #=> true
|
104
|
-
# :aBcDeF.casecmp?(:abcdefg) #=> false
|
105
|
-
# :abcdef.casecmp?(:ABCDEF) #=> true
|
106
|
-
# :"\u{e4 f6 fc}".casecmp?(:"\u{c4 d6 dc}") #=> true
|
107
|
-
#
|
108
|
-
# `nil` is returned if the two symbols have incompatible encodings, or if
|
109
|
-
# `other_symbol` is not a symbol.
|
110
|
-
#
|
111
|
-
# :foo.casecmp?(2) #=> nil
|
112
|
-
# "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym.casecmp?(:"\u{c4 d6 dc}") #=> nil
|
113
|
-
#
|
114
|
-
def casecmp?: (Symbol other) -> bool
|
115
|
-
| (untyped other) -> bool
|
116
|
-
|
117
|
-
# Same as `sym.to_s.downcase.intern`.
|
118
|
-
#
|
119
|
-
def downcase: () -> Symbol
|
120
|
-
| (:ascii | :fold | :lithuanian | :turkic) -> Symbol
|
121
|
-
| (:lithuanian, :turkic) -> Symbol
|
122
|
-
| (:turkic, :lithuanian) -> Symbol
|
123
|
-
|
124
|
-
# Returns whether *sym* is :"" or not.
|
125
|
-
#
|
126
|
-
def empty?: () -> bool
|
127
|
-
|
128
|
-
# Returns the Encoding object that represents the encoding of *sym*.
|
129
|
-
#
|
130
|
-
def encoding: () -> Encoding
|
131
|
-
|
132
|
-
# Returns true if `sym` ends with one of the `suffixes` given.
|
133
|
-
#
|
134
|
-
# :hello.end_with?("ello") #=> true
|
135
|
-
#
|
136
|
-
# # returns true if one of the +suffixes+ matches.
|
137
|
-
# :hello.end_with?("heaven", "ello") #=> true
|
138
|
-
# :hello.end_with?("heaven", "paradise") #=> false
|
139
|
-
#
|
140
|
-
def end_with?: (String str, *String str) -> bool
|
141
|
-
|
142
|
-
# Returns the name or string corresponding to *sym*.
|
143
|
-
#
|
144
|
-
# :fred.id2name #=> "fred"
|
145
|
-
# :ginger.to_s #=> "ginger"
|
146
|
-
#
|
147
|
-
def id2name: () -> String
|
148
|
-
|
149
|
-
# Returns the representation of *sym* as a symbol literal.
|
150
|
-
#
|
151
|
-
# :fred.inspect #=> ":fred"
|
152
|
-
#
|
153
|
-
def inspect: () -> String
|
154
|
-
|
155
|
-
# In general, `to_sym` returns the Symbol corresponding to an object. As *sym*
|
156
|
-
# is already a symbol, `self` is returned in this case.
|
157
|
-
#
|
158
|
-
def intern: () -> self
|
159
|
-
|
160
|
-
# Same as `sym.to_s.length`.
|
161
|
-
#
|
162
|
-
def length: () -> Integer
|
163
|
-
|
164
|
-
# Returns `sym.to_s.match`.
|
165
|
-
#
|
166
|
-
def match: (Regexp | String pattern, ?Integer pos) ?{ (MatchData) -> void } -> MatchData?
|
167
|
-
|
168
|
-
# Returns `sym.to_s.match?`.
|
169
|
-
#
|
170
|
-
def match?: (Regexp | String pattern, ?Integer pos) -> bool
|
171
|
-
|
172
|
-
# Same as `sym.to_s.succ.intern`.
|
173
|
-
#
|
174
|
-
def next: () -> Symbol
|
175
|
-
|
176
|
-
# Same as `sym.to_s.length`.
|
177
|
-
#
|
178
|
-
alias size length
|
179
|
-
|
180
|
-
# Returns `sym.to_s[]`.
|
181
|
-
#
|
182
|
-
alias slice `[]`
|
183
|
-
|
184
|
-
# Returns true if `sym` starts with one of the `prefixes` given. Each of the
|
185
|
-
# `prefixes` should be a String or a Regexp.
|
186
|
-
#
|
187
|
-
# :hello.start_with?("hell") #=> true
|
188
|
-
# :hello.start_with?(/H/i) #=> true
|
189
|
-
#
|
190
|
-
# # returns true if one of the prefixes matches.
|
191
|
-
# :hello.start_with?("heaven", "hell") #=> true
|
192
|
-
# :hello.start_with?("heaven", "paradise") #=> false
|
193
|
-
def start_with?: (String str, *String str) -> bool
|
194
|
-
|
195
|
-
# Same as `sym.to_s.succ.intern`.
|
196
|
-
#
|
197
|
-
alias succ next
|
198
|
-
|
199
|
-
# Same as `sym.to_s.swapcase.intern`.
|
200
|
-
#
|
201
|
-
def swapcase: () -> Symbol
|
202
|
-
| (:ascii | :lithuanian | :turkic) -> Symbol
|
203
|
-
| (:lithuanian, :turkic) -> Symbol
|
204
|
-
| (:turkic, :lithuanian) -> Symbol
|
205
|
-
|
206
|
-
# Returns a *Proc* object which responds to the given method by *sym*.
|
207
|
-
#
|
208
|
-
# (1..3).collect(&:to_s) #=> ["1", "2", "3"]
|
209
|
-
#
|
210
|
-
def to_proc: () -> Proc
|
211
|
-
|
212
|
-
# Returns the name or string corresponding to *sym*.
|
213
|
-
#
|
214
|
-
# :fred.id2name #=> "fred"
|
215
|
-
# :ginger.to_s #=> "ginger"
|
216
|
-
#
|
217
|
-
alias to_s id2name
|
218
|
-
|
219
|
-
# In general, `to_sym` returns the Symbol corresponding to an object. As *sym*
|
220
|
-
# is already a symbol, `self` is returned in this case.
|
221
|
-
#
|
222
|
-
alias to_sym intern
|
223
|
-
|
224
|
-
# Same as `sym.to_s.upcase.intern`.
|
225
|
-
#
|
226
|
-
def upcase: () -> Symbol
|
227
|
-
| (:ascii | :lithuanian | :turkic) -> Symbol
|
228
|
-
| (:lithuanian, :turkic) -> Symbol
|
229
|
-
| (:turkic, :lithuanian) -> Symbol
|
230
|
-
end
|
@@ -1,1112 +0,0 @@
|
|
1
|
-
# Threads are the Ruby implementation for a concurrent programming model.
|
2
|
-
#
|
3
|
-
# Programs that require multiple threads of execution are a perfect
|
4
|
-
# candidate for Ruby's [Thread](Thread) class.
|
5
|
-
#
|
6
|
-
# For example, we can create a new thread separate from the main thread's
|
7
|
-
# execution using [::new](Thread#method-c-new).
|
8
|
-
#
|
9
|
-
# ```ruby
|
10
|
-
# thr = Thread.new { puts "Whats the big deal" }
|
11
|
-
# ```
|
12
|
-
#
|
13
|
-
# Then we are able to pause the execution of the main thread and allow our
|
14
|
-
# new thread to finish, using
|
15
|
-
# [join](Thread#method-i-join):
|
16
|
-
#
|
17
|
-
# ```ruby
|
18
|
-
# thr.join #=> "Whats the big deal"
|
19
|
-
# ```
|
20
|
-
#
|
21
|
-
# If we don't call `thr.join` before the main thread terminates, then all
|
22
|
-
# other threads including `thr` will be killed.
|
23
|
-
#
|
24
|
-
# Alternatively, you can use an array for handling multiple threads at
|
25
|
-
# once, like in the following example:
|
26
|
-
#
|
27
|
-
# ```ruby
|
28
|
-
# threads = []
|
29
|
-
# threads << Thread.new { puts "Whats the big deal" }
|
30
|
-
# threads << Thread.new { 3.times { puts "Threads are fun!" } }
|
31
|
-
# ```
|
32
|
-
#
|
33
|
-
# After creating a few threads we wait for them all to finish
|
34
|
-
# consecutively.
|
35
|
-
#
|
36
|
-
# ```ruby
|
37
|
-
# threads.each { |thr| thr.join }
|
38
|
-
# ```
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# In order to create new threads, Ruby provides
|
42
|
-
# [::new](Thread#method-c-new),
|
43
|
-
# [::start](Thread#method-c-start), and
|
44
|
-
# [::fork](Thread#method-c-fork). A block must be
|
45
|
-
# provided with each of these methods, otherwise a
|
46
|
-
# [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html) will be
|
47
|
-
# raised.
|
48
|
-
#
|
49
|
-
# When subclassing the [Thread](Thread) class, the
|
50
|
-
# `initialize` method of your subclass will be ignored by
|
51
|
-
# [::start](Thread#method-c-start) and
|
52
|
-
# [::fork](Thread#method-c-fork). Otherwise, be sure
|
53
|
-
# to call super in your `initialize` method.
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# For terminating threads, Ruby provides a variety of ways to do this.
|
57
|
-
#
|
58
|
-
# The class method [::kill](Thread#method-c-kill), is
|
59
|
-
# meant to exit a given thread:
|
60
|
-
#
|
61
|
-
# thr = Thread.new { ... }
|
62
|
-
# Thread.kill(thr) # sends exit() to thr
|
63
|
-
#
|
64
|
-
# Alternatively, you can use the instance method
|
65
|
-
# [exit](Thread#method-i-exit), or any of its aliases
|
66
|
-
# [kill](Thread#method-i-kill) or
|
67
|
-
# [terminate](Thread#method-i-terminate).
|
68
|
-
#
|
69
|
-
# ```ruby
|
70
|
-
# thr.exit
|
71
|
-
# ```
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# Ruby provides a few instance methods for querying the state of a given
|
75
|
-
# thread. To get a string with the current thread's state use
|
76
|
-
# [status](Thread#method-i-status)
|
77
|
-
#
|
78
|
-
# ```ruby
|
79
|
-
# thr = Thread.new { sleep }
|
80
|
-
# thr.status # => "sleep"
|
81
|
-
# thr.exit
|
82
|
-
# thr.status # => false
|
83
|
-
# ```
|
84
|
-
#
|
85
|
-
# You can also use [alive?](Thread#method-i-alive-3F)
|
86
|
-
# to tell if the thread is running or sleeping, and
|
87
|
-
# [stop?](Thread#method-i-stop-3F) if the thread is
|
88
|
-
# dead or sleeping.
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# Since threads are created with blocks, the same rules apply to other
|
92
|
-
# Ruby blocks for variable scope. Any local variables created within this
|
93
|
-
# block are accessible to only this thread.
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# Each fiber has its own bucket for
|
97
|
-
# [\#\[\]](Thread#method-i-5B-5D) storage. When you
|
98
|
-
# set a new fiber-local it is only accessible within this
|
99
|
-
# [Fiber](https://ruby-doc.org/core-2.6.3/Fiber.html). To illustrate:
|
100
|
-
#
|
101
|
-
# ```ruby
|
102
|
-
# Thread.new {
|
103
|
-
# Thread.current[:foo] = "bar"
|
104
|
-
# Fiber.new {
|
105
|
-
# p Thread.current[:foo] # => nil
|
106
|
-
# }.resume
|
107
|
-
# }.join
|
108
|
-
# ```
|
109
|
-
#
|
110
|
-
# This example uses [\[\]](Thread#method-i-5B-5D) for
|
111
|
-
# getting and [\[\]=](Thread#method-i-5B-5D-3D) for
|
112
|
-
# setting fiber-locals, you can also use
|
113
|
-
# [keys](Thread#method-i-keys) to list the
|
114
|
-
# fiber-locals for a given thread and
|
115
|
-
# [key?](Thread#method-i-key-3F) to check if a
|
116
|
-
# fiber-local exists.
|
117
|
-
#
|
118
|
-
# When it comes to thread-locals, they are accessible within the entire
|
119
|
-
# scope of the thread. Given the following example:
|
120
|
-
#
|
121
|
-
# ```ruby
|
122
|
-
# Thread.new{
|
123
|
-
# Thread.current.thread_variable_set(:foo, 1)
|
124
|
-
# p Thread.current.thread_variable_get(:foo) # => 1
|
125
|
-
# Fiber.new{
|
126
|
-
# Thread.current.thread_variable_set(:foo, 2)
|
127
|
-
# p Thread.current.thread_variable_get(:foo) # => 2
|
128
|
-
# }.resume
|
129
|
-
# p Thread.current.thread_variable_get(:foo) # => 2
|
130
|
-
# }.join
|
131
|
-
# ```
|
132
|
-
#
|
133
|
-
# You can see that the thread-local `:foo` carried over into the fiber and
|
134
|
-
# was changed to `2` by the end of the thread.
|
135
|
-
#
|
136
|
-
# This example makes use of
|
137
|
-
# [thread\_variable\_set](Thread#method-i-thread_variable_set)
|
138
|
-
# to create new thread-locals, and
|
139
|
-
# [thread\_variable\_get](Thread#method-i-thread_variable_get)
|
140
|
-
# to reference them.
|
141
|
-
#
|
142
|
-
# There is also
|
143
|
-
# [thread\_variables](Thread#method-i-thread_variables)
|
144
|
-
# to list all thread-locals, and
|
145
|
-
# [thread\_variable?](Thread#method-i-thread_variable-3F)
|
146
|
-
# to check if a given thread-local exists.
|
147
|
-
#
|
148
|
-
#
|
149
|
-
# Any thread can raise an exception using the
|
150
|
-
# [raise](Thread#method-i-raise) instance method,
|
151
|
-
# which operates similarly to
|
152
|
-
# [Kernel\#raise](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-raise)
|
153
|
-
# .
|
154
|
-
#
|
155
|
-
# However, it's important to note that an exception that occurs in any
|
156
|
-
# thread except the main thread depends on
|
157
|
-
# [abort\_on\_exception](Thread#method-i-abort_on_exception)
|
158
|
-
# . This option is `false` by default, meaning that any unhandled
|
159
|
-
# exception will cause the thread to terminate silently when waited on by
|
160
|
-
# either [join](Thread#method-i-join) or
|
161
|
-
# [value](Thread#method-i-value). You can change this
|
162
|
-
# default by either
|
163
|
-
# [abort\_on\_exception=](Thread#method-i-abort_on_exception-3D)
|
164
|
-
# `true` or setting $DEBUG to `true` .
|
165
|
-
#
|
166
|
-
# With the addition of the class method
|
167
|
-
# [::handle\_interrupt](Thread#method-c-handle_interrupt)
|
168
|
-
# , you can now handle exceptions asynchronously with threads.
|
169
|
-
#
|
170
|
-
#
|
171
|
-
# Ruby provides a few ways to support scheduling threads in your program.
|
172
|
-
#
|
173
|
-
# The first way is by using the class method
|
174
|
-
# [::stop](Thread#method-c-stop), to put the current
|
175
|
-
# running thread to sleep and schedule the execution of another thread.
|
176
|
-
#
|
177
|
-
# Once a thread is asleep, you can use the instance method
|
178
|
-
# [wakeup](Thread#method-i-wakeup) to mark your thread
|
179
|
-
# as eligible for scheduling.
|
180
|
-
#
|
181
|
-
# You can also try [::pass](Thread#method-c-pass),
|
182
|
-
# which attempts to pass execution to another thread but is dependent on
|
183
|
-
# the OS whether a running thread will switch or not. The same goes for
|
184
|
-
# [priority](Thread#method-i-priority), which lets
|
185
|
-
# you hint to the thread scheduler which threads you want to take
|
186
|
-
# precedence when passing execution. This method is also dependent on the
|
187
|
-
# OS and may be ignored on some platforms.
|
188
|
-
class Thread < Object
|
189
|
-
def self.current: () -> Thread
|
190
|
-
|
191
|
-
# Returns the main thread.
|
192
|
-
def self.main: () -> Thread
|
193
|
-
|
194
|
-
def []: (String | Symbol key) -> untyped
|
195
|
-
|
196
|
-
# Attribute Assignment—Sets or creates the value of a fiber-local
|
197
|
-
# variable, using either a symbol or a string.
|
198
|
-
#
|
199
|
-
# See also [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D).
|
200
|
-
#
|
201
|
-
# For thread-local variables, please see
|
202
|
-
# [thread\_variable\_set](Thread.downloaded.ruby_doc#method-i-thread_variable_set)
|
203
|
-
# and
|
204
|
-
# [thread\_variable\_get](Thread.downloaded.ruby_doc#method-i-thread_variable_get)
|
205
|
-
# .
|
206
|
-
def []=: (String | Symbol key, untyped value) -> untyped
|
207
|
-
|
208
|
-
def alive?: () -> bool
|
209
|
-
|
210
|
-
# Terminates `thr` and schedules another thread to be run.
|
211
|
-
#
|
212
|
-
# If this thread is already marked to be killed,
|
213
|
-
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
214
|
-
# [Thread](Thread.downloaded.ruby_doc).
|
215
|
-
#
|
216
|
-
# If this is the main thread, or the last thread, exits the process.
|
217
|
-
def kill: () -> Thread?
|
218
|
-
|
219
|
-
# Returns the status of the thread-local “abort on exception” condition
|
220
|
-
# for this `thr` .
|
221
|
-
#
|
222
|
-
# The default is `false` .
|
223
|
-
#
|
224
|
-
# See also
|
225
|
-
# [abort\_on\_exception=](Thread.downloaded.ruby_doc#method-i-abort_on_exception-3D)
|
226
|
-
# .
|
227
|
-
#
|
228
|
-
# There is also a class level method to set this for all threads, see
|
229
|
-
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
230
|
-
# .
|
231
|
-
def abort_on_exception: () -> bool
|
232
|
-
|
233
|
-
# When set to `true`, if this `thr` is aborted by an exception, the
|
234
|
-
# raised exception will be re-raised in the main thread.
|
235
|
-
#
|
236
|
-
# See also
|
237
|
-
# [abort\_on\_exception](Thread.downloaded.ruby_doc#method-i-abort_on_exception)
|
238
|
-
# .
|
239
|
-
#
|
240
|
-
# There is also a class level method to set this for all threads, see
|
241
|
-
# [::abort\_on\_exception=](Thread.downloaded.ruby_doc#method-c-abort_on_exception-3D)
|
242
|
-
# .
|
243
|
-
def abort_on_exception=: (bool abort_on_exception) -> untyped
|
244
|
-
|
245
|
-
# Adds *proc* as a handler for tracing.
|
246
|
-
#
|
247
|
-
# See
|
248
|
-
# [\#set\_trace\_func](Thread.downloaded.ruby_doc#method-i-set_trace_func)
|
249
|
-
# and
|
250
|
-
# [Kernel\#set\_trace\_func](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-set_trace_func)
|
251
|
-
# .
|
252
|
-
def add_trace_func: (untyped proc) -> untyped
|
253
|
-
|
254
|
-
# Returns the current backtrace of the target thread.
|
255
|
-
def backtrace: (*untyped args) -> ::Array[untyped]
|
256
|
-
|
257
|
-
# Returns the execution stack for the target thread—an array containing
|
258
|
-
# backtrace location objects.
|
259
|
-
#
|
260
|
-
# See
|
261
|
-
# [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
|
262
|
-
# for more information.
|
263
|
-
#
|
264
|
-
# This method behaves similarly to
|
265
|
-
# [Kernel\#caller\_locations](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-caller_locations)
|
266
|
-
# except it applies to a specific thread.
|
267
|
-
def backtrace_locations: (*untyped args) -> ::Array[untyped]?
|
268
|
-
|
269
|
-
# Terminates `thr` and schedules another thread to be run.
|
270
|
-
#
|
271
|
-
# If this thread is already marked to be killed,
|
272
|
-
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
273
|
-
# [Thread](Thread.downloaded.ruby_doc).
|
274
|
-
#
|
275
|
-
# If this is the main thread, or the last thread, exits the process.
|
276
|
-
def exit: () -> Thread?
|
277
|
-
|
278
|
-
# Returns a fiber-local for the given key. If the key can’t be found,
|
279
|
-
# there are several options: With no other arguments, it will raise a
|
280
|
-
# `KeyError` exception; if *default* is given, then that will be returned;
|
281
|
-
# if the optional code block is specified, then that will be run and its
|
282
|
-
# result returned. See [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D)
|
283
|
-
# and
|
284
|
-
# [Hash\#fetch](https://ruby-doc.org/core-2.6.3/Hash.html#method-i-fetch)
|
285
|
-
# .
|
286
|
-
def fetch: (*untyped sym) -> untyped
|
287
|
-
|
288
|
-
def group: () -> ThreadGroup?
|
289
|
-
|
290
|
-
def initialize: (*untyped args) -> Thread
|
291
|
-
|
292
|
-
# The calling thread will suspend execution and run this `thr` .
|
293
|
-
#
|
294
|
-
# Does not return until `thr` exits or until the given `limit` seconds
|
295
|
-
# have passed.
|
296
|
-
#
|
297
|
-
# If the time limit expires, `nil` will be returned, otherwise `thr` is
|
298
|
-
# returned.
|
299
|
-
#
|
300
|
-
# Any threads not joined will be killed when the main program exits.
|
301
|
-
#
|
302
|
-
# If `thr` had previously raised an exception and the
|
303
|
-
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
304
|
-
# or $DEBUG flags are not set, (so the exception has not yet been
|
305
|
-
# processed), it will be processed at this time.
|
306
|
-
#
|
307
|
-
# ```ruby
|
308
|
-
# a = Thread.new { print "a"; sleep(10); print "b"; print "c" }
|
309
|
-
# x = Thread.new { print "x"; Thread.pass; print "y"; print "z" }
|
310
|
-
# x.join # Let thread x finish, thread a will be killed on exit.
|
311
|
-
# #=> "axyz"
|
312
|
-
# ```
|
313
|
-
#
|
314
|
-
# The following example illustrates the `limit` parameter.
|
315
|
-
#
|
316
|
-
# ```ruby
|
317
|
-
# y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }}
|
318
|
-
# puts "Waiting" until y.join(0.15)
|
319
|
-
# ```
|
320
|
-
#
|
321
|
-
# This will produce:
|
322
|
-
#
|
323
|
-
# tick...
|
324
|
-
# Waiting
|
325
|
-
# tick...
|
326
|
-
# Waiting
|
327
|
-
# tick...
|
328
|
-
# tick...
|
329
|
-
def join: (*untyped limit) -> Thread
|
330
|
-
|
331
|
-
# Returns `true` if the given string (or symbol) exists as a fiber-local
|
332
|
-
# variable.
|
333
|
-
#
|
334
|
-
# ```ruby
|
335
|
-
# me = Thread.current
|
336
|
-
# me[:oliver] = "a"
|
337
|
-
# me.key?(:oliver) #=> true
|
338
|
-
# me.key?(:stanley) #=> false
|
339
|
-
# ```
|
340
|
-
def key?: (Symbol sym) -> bool
|
341
|
-
|
342
|
-
def keys: () -> ::Array[Symbol]
|
343
|
-
|
344
|
-
# show the name of the thread.
|
345
|
-
def name: () -> String
|
346
|
-
|
347
|
-
# set given name to the ruby thread. On some platform, it may set the name
|
348
|
-
# to pthread and/or kernel.
|
349
|
-
def name=: (untyped name) -> untyped
|
350
|
-
|
351
|
-
# Returns whether or not the asynchronous queue is empty for the target
|
352
|
-
# thread.
|
353
|
-
#
|
354
|
-
# If `error` is given, then check only for `error` type deferred events.
|
355
|
-
#
|
356
|
-
# See
|
357
|
-
# [::pending\_interrupt?](Thread.downloaded.ruby_doc#method-c-pending_interrupt-3F)
|
358
|
-
# for more information.
|
359
|
-
def pending_interrupt?: (*untyped args) -> bool
|
360
|
-
|
361
|
-
# Returns the priority of *thr* . Default is inherited from the current
|
362
|
-
# thread which creating the new thread, or zero for the initial main
|
363
|
-
# thread; higher-priority thread will run more frequently than
|
364
|
-
# lower-priority threads (but lower-priority threads can also run).
|
365
|
-
#
|
366
|
-
# This is just hint for Ruby thread scheduler. It may be ignored on some
|
367
|
-
# platform.
|
368
|
-
#
|
369
|
-
# ```ruby
|
370
|
-
# Thread.current.priority #=> 0
|
371
|
-
# ```
|
372
|
-
def priority: () -> Integer
|
373
|
-
|
374
|
-
# Sets the priority of *thr* to *integer* . Higher-priority threads will
|
375
|
-
# run more frequently than lower-priority threads (but lower-priority
|
376
|
-
# threads can also run).
|
377
|
-
#
|
378
|
-
# This is just hint for Ruby thread scheduler. It may be ignored on some
|
379
|
-
# platform.
|
380
|
-
#
|
381
|
-
# ```ruby
|
382
|
-
# count1 = count2 = 0
|
383
|
-
# a = Thread.new do
|
384
|
-
# loop { count1 += 1 }
|
385
|
-
# end
|
386
|
-
# a.priority = -1
|
387
|
-
#
|
388
|
-
# b = Thread.new do
|
389
|
-
# loop { count2 += 1 }
|
390
|
-
# end
|
391
|
-
# b.priority = -2
|
392
|
-
# sleep 1 #=> 1
|
393
|
-
# count1 #=> 622504
|
394
|
-
# count2 #=> 5832
|
395
|
-
# ```
|
396
|
-
def priority=: (Integer priority) -> untyped
|
397
|
-
|
398
|
-
# Returns the status of the thread-local “report on exception” condition
|
399
|
-
# for this `thr` .
|
400
|
-
#
|
401
|
-
# The default value when creating a [Thread](Thread.downloaded.ruby_doc)
|
402
|
-
# is the value of the global flag
|
403
|
-
# [::report\_on\_exception](Thread.downloaded.ruby_doc#method-c-report_on_exception)
|
404
|
-
# .
|
405
|
-
#
|
406
|
-
# See also
|
407
|
-
# [report\_on\_exception=](Thread.downloaded.ruby_doc#method-i-report_on_exception-3D)
|
408
|
-
# .
|
409
|
-
#
|
410
|
-
# There is also a class level method to set this for all new threads, see
|
411
|
-
# [::report\_on\_exception=](Thread.downloaded.ruby_doc#method-c-report_on_exception-3D)
|
412
|
-
# .
|
413
|
-
def report_on_exception: () -> bool
|
414
|
-
|
415
|
-
# When set to `true`, a message is printed on $stderr if an exception
|
416
|
-
# kills this `thr` . See
|
417
|
-
# [::report\_on\_exception](Thread.downloaded.ruby_doc#method-c-report_on_exception)
|
418
|
-
# for details.
|
419
|
-
#
|
420
|
-
# See also
|
421
|
-
# [report\_on\_exception](Thread.downloaded.ruby_doc#method-i-report_on_exception)
|
422
|
-
# .
|
423
|
-
#
|
424
|
-
# There is also a class level method to set this for all new threads, see
|
425
|
-
# [::report\_on\_exception=](Thread.downloaded.ruby_doc#method-c-report_on_exception-3D)
|
426
|
-
# .
|
427
|
-
def report_on_exception=: (bool report_on_exception) -> untyped
|
428
|
-
|
429
|
-
# Wakes up `thr`, making it eligible for scheduling.
|
430
|
-
#
|
431
|
-
# ```ruby
|
432
|
-
# a = Thread.new { puts "a"; Thread.stop; puts "c" }
|
433
|
-
# sleep 0.1 while a.status!='sleep'
|
434
|
-
# puts "Got here"
|
435
|
-
# a.run
|
436
|
-
# a.join
|
437
|
-
# ```
|
438
|
-
#
|
439
|
-
# This will produce:
|
440
|
-
#
|
441
|
-
# ```ruby
|
442
|
-
# a
|
443
|
-
# Got here
|
444
|
-
# c
|
445
|
-
# ```
|
446
|
-
#
|
447
|
-
# See also the instance method
|
448
|
-
# [wakeup](Thread.downloaded.ruby_doc#method-i-wakeup).
|
449
|
-
def run: () -> Thread
|
450
|
-
|
451
|
-
# Returns the safe level.
|
452
|
-
#
|
453
|
-
# This method is obsolete because $SAFE is a process global state. Simply
|
454
|
-
# check $SAFE.
|
455
|
-
def safe_level: () -> Integer
|
456
|
-
|
457
|
-
def status: () -> (String | bool)?
|
458
|
-
|
459
|
-
# Returns `true` if `thr` is dead or sleeping.
|
460
|
-
#
|
461
|
-
# ```ruby
|
462
|
-
# a = Thread.new { Thread.stop }
|
463
|
-
# b = Thread.current
|
464
|
-
# a.stop? #=> true
|
465
|
-
# b.stop? #=> false
|
466
|
-
# ```
|
467
|
-
#
|
468
|
-
# See also [alive?](Thread.downloaded.ruby_doc#method-i-alive-3F) and
|
469
|
-
# [status](Thread.downloaded.ruby_doc#method-i-status).
|
470
|
-
def `stop?`: () -> bool
|
471
|
-
|
472
|
-
# Terminates `thr` and schedules another thread to be run.
|
473
|
-
#
|
474
|
-
# If this thread is already marked to be killed,
|
475
|
-
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
476
|
-
# [Thread](Thread.downloaded.ruby_doc).
|
477
|
-
#
|
478
|
-
# If this is the main thread, or the last thread, exits the process.
|
479
|
-
def terminate: () -> Thread?
|
480
|
-
|
481
|
-
# Returns `true` if the given string (or symbol) exists as a thread-local
|
482
|
-
# variable.
|
483
|
-
#
|
484
|
-
# ```ruby
|
485
|
-
# me = Thread.current
|
486
|
-
# me.thread_variable_set(:oliver, "a")
|
487
|
-
# me.thread_variable?(:oliver) #=> true
|
488
|
-
# me.thread_variable?(:stanley) #=> false
|
489
|
-
# ```
|
490
|
-
#
|
491
|
-
# Note that these are not fiber local variables. Please see
|
492
|
-
# [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D) and
|
493
|
-
# [\#thread\_variable\_get](Thread.downloaded.ruby_doc#method-i-thread_variable_get)
|
494
|
-
# for more details.
|
495
|
-
def thread_variable?: (String | Symbol key) -> bool
|
496
|
-
|
497
|
-
# Returns the value of a thread local variable that has been set. Note
|
498
|
-
# that these are different than fiber local values. For fiber local
|
499
|
-
# values, please see [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D)
|
500
|
-
# and [\#\[\]=](Thread.downloaded.ruby_doc#method-i-5B-5D-3D).
|
501
|
-
#
|
502
|
-
# [Thread](Thread.downloaded.ruby_doc) local values are carried along with
|
503
|
-
# threads, and do not respect fibers. For example:
|
504
|
-
#
|
505
|
-
# ```ruby
|
506
|
-
# Thread.new {
|
507
|
-
# Thread.current.thread_variable_set("foo", "bar") # set a thread local
|
508
|
-
# Thread.current["foo"] = "bar" # set a fiber local
|
509
|
-
#
|
510
|
-
# Fiber.new {
|
511
|
-
# Fiber.yield [
|
512
|
-
# Thread.current.thread_variable_get("foo"), # get the thread local
|
513
|
-
# Thread.current["foo"], # get the fiber local
|
514
|
-
# ]
|
515
|
-
# }.resume
|
516
|
-
# }.join.value # => ['bar', nil]
|
517
|
-
# ```
|
518
|
-
#
|
519
|
-
# The value “bar” is returned for the thread local, where nil is returned
|
520
|
-
# for the fiber local. The fiber is executed in the same thread, so the
|
521
|
-
# thread local values are available.
|
522
|
-
def thread_variable_get: (untyped key) -> untyped
|
523
|
-
|
524
|
-
# Sets a thread local with `key` to `value` . Note that these are local to
|
525
|
-
# threads, and not to fibers. Please see
|
526
|
-
# [\#thread\_variable\_get](Thread.downloaded.ruby_doc#method-i-thread_variable_get)
|
527
|
-
# and [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D) for more
|
528
|
-
# information.
|
529
|
-
def thread_variable_set: (untyped key, untyped value) -> untyped
|
530
|
-
|
531
|
-
def thread_variables: () -> ::Array[Symbol]
|
532
|
-
|
533
|
-
# Waits for `thr` to complete, using
|
534
|
-
# [join](Thread.downloaded.ruby_doc#method-i-join), and returns its value
|
535
|
-
# or raises the exception which terminated the thread.
|
536
|
-
#
|
537
|
-
# ```ruby
|
538
|
-
# a = Thread.new { 2 + 2 }
|
539
|
-
# a.value #=> 4
|
540
|
-
#
|
541
|
-
# b = Thread.new { raise 'something went wrong' }
|
542
|
-
# b.value #=> RuntimeError: something went wrong
|
543
|
-
# ```
|
544
|
-
def value: () -> Object
|
545
|
-
|
546
|
-
# Marks a given thread as eligible for scheduling, however it may still
|
547
|
-
# remain blocked on I/O.
|
548
|
-
#
|
549
|
-
# **Note:** This does not invoke the scheduler, see
|
550
|
-
# [run](Thread.downloaded.ruby_doc#method-i-run) for more information.
|
551
|
-
#
|
552
|
-
# ```ruby
|
553
|
-
# c = Thread.new { Thread.stop; puts "hey!" }
|
554
|
-
# sleep 0.1 while c.status!='sleep'
|
555
|
-
# c.wakeup
|
556
|
-
# c.join
|
557
|
-
# #=> "hey!"
|
558
|
-
# ```
|
559
|
-
def wakeup: () -> Thread
|
560
|
-
|
561
|
-
# Returns the status of the global “abort on exception” condition.
|
562
|
-
#
|
563
|
-
# The default is `false` .
|
564
|
-
#
|
565
|
-
# When set to `true`, if any thread is aborted by an exception, the
|
566
|
-
# raised exception will be re-raised in the main thread.
|
567
|
-
#
|
568
|
-
# Can also be specified by the global $DEBUG flag or command line option
|
569
|
-
# `-d` .
|
570
|
-
#
|
571
|
-
# See also
|
572
|
-
# [::abort\_on\_exception=](Thread.downloaded.ruby_doc#method-c-abort_on_exception-3D)
|
573
|
-
# .
|
574
|
-
#
|
575
|
-
# There is also an instance level method to set this for a specific
|
576
|
-
# thread, see
|
577
|
-
# [abort\_on\_exception](Thread.downloaded.ruby_doc#method-i-abort_on_exception)
|
578
|
-
# .
|
579
|
-
def self.abort_on_exception: () -> untyped
|
580
|
-
|
581
|
-
# When set to `true`, if any thread is aborted by an exception, the
|
582
|
-
# raised exception will be re-raised in the main thread. Returns the new
|
583
|
-
# state.
|
584
|
-
#
|
585
|
-
# ```ruby
|
586
|
-
# Thread.abort_on_exception = true
|
587
|
-
# t1 = Thread.new do
|
588
|
-
# puts "In new thread"
|
589
|
-
# raise "Exception from thread"
|
590
|
-
# end
|
591
|
-
# sleep(1)
|
592
|
-
# puts "not reached"
|
593
|
-
# ```
|
594
|
-
#
|
595
|
-
# This will produce:
|
596
|
-
#
|
597
|
-
# In new thread
|
598
|
-
# prog.rb:4: Exception from thread (RuntimeError)
|
599
|
-
# from prog.rb:2:in `initialize'
|
600
|
-
# from prog.rb:2:in `new'
|
601
|
-
# from prog.rb:2
|
602
|
-
#
|
603
|
-
# See also
|
604
|
-
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
605
|
-
# .
|
606
|
-
#
|
607
|
-
# There is also an instance level method to set this for a specific
|
608
|
-
# thread, see
|
609
|
-
# [abort\_on\_exception=](Thread.downloaded.ruby_doc#method-i-abort_on_exception-3D)
|
610
|
-
# .
|
611
|
-
def self.abort_on_exception=: (untyped abort_on_exception) -> untyped
|
612
|
-
|
613
|
-
# Wraps the block in a single, VM-global
|
614
|
-
# [Mutex\#synchronize](https://ruby-doc.org/core-2.6.3/Mutex.html#method-i-synchronize)
|
615
|
-
# , returning the value of the block. A thread executing inside the
|
616
|
-
# exclusive section will only block other threads which also use the
|
617
|
-
# [::exclusive](Thread.downloaded.ruby_doc#method-c-exclusive) mechanism.
|
618
|
-
def self.exclusive: () { () -> untyped } -> untyped
|
619
|
-
|
620
|
-
# Terminates the currently running thread and schedules another thread to
|
621
|
-
# be run.
|
622
|
-
#
|
623
|
-
# If this thread is already marked to be killed,
|
624
|
-
# [::exit](Thread.downloaded.ruby_doc#method-c-exit) returns the
|
625
|
-
# [Thread](Thread.downloaded.ruby_doc).
|
626
|
-
#
|
627
|
-
# If this is the main thread, or the last thread, exit the process.
|
628
|
-
def self.exit: () -> untyped
|
629
|
-
|
630
|
-
# Basically the same as [::new](Thread.downloaded.ruby_doc#method-c-new).
|
631
|
-
# However, if class [Thread](Thread.downloaded.ruby_doc) is subclassed,
|
632
|
-
# then calling `start` in that subclass will not invoke the subclass’s
|
633
|
-
# `initialize` method.
|
634
|
-
def self.fork: (*untyped args) -> untyped
|
635
|
-
|
636
|
-
# Changes asynchronous interrupt timing.
|
637
|
-
#
|
638
|
-
# *interrupt* means asynchronous event and corresponding procedure by
|
639
|
-
# [\#raise](Thread.downloaded.ruby_doc#method-i-raise),
|
640
|
-
# [\#kill](Thread.downloaded.ruby_doc#method-i-kill), signal trap (not
|
641
|
-
# supported yet) and main thread termination (if main thread terminates,
|
642
|
-
# then all other thread will be killed).
|
643
|
-
#
|
644
|
-
# The given `hash` has pairs like `ExceptionClass => :TimingSymbol` .
|
645
|
-
# Where the ExceptionClass is the interrupt handled by the given block.
|
646
|
-
# The TimingSymbol can be one of the following symbols:
|
647
|
-
#
|
648
|
-
# - `:immediate`
|
649
|
-
# Invoke interrupts immediately.
|
650
|
-
#
|
651
|
-
# - `:on_blocking`
|
652
|
-
# Invoke interrupts while *BlockingOperation* .
|
653
|
-
#
|
654
|
-
# - `:never`
|
655
|
-
# Never invoke all interrupts.
|
656
|
-
#
|
657
|
-
# *BlockingOperation* means that the operation will block the calling
|
658
|
-
# thread, such as read and write. On CRuby implementation,
|
659
|
-
# *BlockingOperation* is any operation executed without GVL.
|
660
|
-
#
|
661
|
-
# Masked asynchronous interrupts are delayed until they are enabled. This
|
662
|
-
# method is similar to sigprocmask(3).
|
663
|
-
#
|
664
|
-
#
|
665
|
-
# Asynchronous interrupts are difficult to use.
|
666
|
-
#
|
667
|
-
# If you need to communicate between threads, please consider to use
|
668
|
-
# another way such as [Queue](https://ruby-doc.org/core-2.6.3/Queue.html)
|
669
|
-
# .
|
670
|
-
#
|
671
|
-
# Or use them with deep understanding about this method.
|
672
|
-
#
|
673
|
-
#
|
674
|
-
# In this example, we can guard from
|
675
|
-
# [\#raise](Thread.downloaded.ruby_doc#method-i-raise) exceptions.
|
676
|
-
#
|
677
|
-
# Using the `:never` TimingSymbol the
|
678
|
-
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
679
|
-
# exception will always be ignored in the first block of the main thread.
|
680
|
-
# In the second
|
681
|
-
# [::handle\_interrupt](Thread.downloaded.ruby_doc#method-c-handle_interrupt)
|
682
|
-
# block we can purposefully handle
|
683
|
-
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
684
|
-
# exceptions.
|
685
|
-
#
|
686
|
-
# ```ruby
|
687
|
-
# th = Thread.new do
|
688
|
-
# Thread.handle_interrupt(RuntimeError => :never) {
|
689
|
-
# begin
|
690
|
-
# # You can write resource allocation code safely.
|
691
|
-
# Thread.handle_interrupt(RuntimeError => :immediate) {
|
692
|
-
# # ...
|
693
|
-
# }
|
694
|
-
# ensure
|
695
|
-
# # You can write resource deallocation code safely.
|
696
|
-
# end
|
697
|
-
# }
|
698
|
-
# end
|
699
|
-
# Thread.pass
|
700
|
-
# # ...
|
701
|
-
# th.raise "stop"
|
702
|
-
# ```
|
703
|
-
#
|
704
|
-
# While we are ignoring the
|
705
|
-
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
706
|
-
# exception, it’s safe to write our resource allocation code. Then, the
|
707
|
-
# ensure block is where we can safely deallocate your resources.
|
708
|
-
#
|
709
|
-
#
|
710
|
-
# In the next example, we will guard from the Timeout::Error exception.
|
711
|
-
# This will help prevent from leaking resources when Timeout::Error
|
712
|
-
# exceptions occur during normal ensure clause. For this example we use
|
713
|
-
# the help of the standard library Timeout, from lib/timeout.rb
|
714
|
-
#
|
715
|
-
# ```ruby
|
716
|
-
# require 'timeout'
|
717
|
-
# Thread.handle_interrupt(Timeout::Error => :never) {
|
718
|
-
# timeout(10){
|
719
|
-
# # Timeout::Error doesn't occur here
|
720
|
-
# Thread.handle_interrupt(Timeout::Error => :on_blocking) {
|
721
|
-
# # possible to be killed by Timeout::Error
|
722
|
-
# # while blocking operation
|
723
|
-
# }
|
724
|
-
# # Timeout::Error doesn't occur here
|
725
|
-
# }
|
726
|
-
# }
|
727
|
-
# ```
|
728
|
-
#
|
729
|
-
# In the first part of the `timeout` block, we can rely on Timeout::Error
|
730
|
-
# being ignored. Then in the `Timeout::Error => :on_blocking` block, any
|
731
|
-
# operation that will block the calling thread is susceptible to a
|
732
|
-
# Timeout::Error exception being raised.
|
733
|
-
#
|
734
|
-
#
|
735
|
-
# It’s possible to stack multiple levels of
|
736
|
-
# [::handle\_interrupt](Thread.downloaded.ruby_doc#method-c-handle_interrupt)
|
737
|
-
# blocks in order to control more than one ExceptionClass and TimingSymbol
|
738
|
-
# at a time.
|
739
|
-
#
|
740
|
-
# ```ruby
|
741
|
-
# Thread.handle_interrupt(FooError => :never) {
|
742
|
-
# Thread.handle_interrupt(BarError => :never) {
|
743
|
-
# # FooError and BarError are prohibited.
|
744
|
-
# }
|
745
|
-
# }
|
746
|
-
# ```
|
747
|
-
#
|
748
|
-
#
|
749
|
-
# All exceptions inherited from the ExceptionClass parameter will be
|
750
|
-
# considered.
|
751
|
-
#
|
752
|
-
# ```ruby
|
753
|
-
# Thread.handle_interrupt(Exception => :never) {
|
754
|
-
# # all exceptions inherited from Exception are prohibited.
|
755
|
-
# }
|
756
|
-
# ```
|
757
|
-
def self.handle_interrupt: (untyped hash) -> untyped
|
758
|
-
|
759
|
-
def self.kill: (Thread thread) -> untyped
|
760
|
-
|
761
|
-
def self.list: () -> untyped
|
762
|
-
|
763
|
-
# Give the thread scheduler a hint to pass execution to another thread. A
|
764
|
-
# running thread may or may not switch, it depends on OS and processor.
|
765
|
-
def self.pass: () -> untyped
|
766
|
-
|
767
|
-
# Returns whether or not the asynchronous queue is empty.
|
768
|
-
#
|
769
|
-
# Since
|
770
|
-
# [::handle\_interrupt](Thread.downloaded.ruby_doc#method-c-handle_interrupt)
|
771
|
-
# can be used to defer asynchronous events, this method can be used to
|
772
|
-
# determine if there are any deferred events.
|
773
|
-
#
|
774
|
-
# If you find this method returns true, then you may finish `:never`
|
775
|
-
# blocks.
|
776
|
-
#
|
777
|
-
# For example, the following method processes deferred asynchronous events
|
778
|
-
# immediately.
|
779
|
-
#
|
780
|
-
# ```ruby
|
781
|
-
# def Thread.kick_interrupt_immediately
|
782
|
-
# Thread.handle_interrupt(Object => :immediate) {
|
783
|
-
# Thread.pass
|
784
|
-
# }
|
785
|
-
# end
|
786
|
-
# ```
|
787
|
-
#
|
788
|
-
# If `error` is given, then check only for `error` type deferred events.
|
789
|
-
#
|
790
|
-
#
|
791
|
-
# th = Thread.new{
|
792
|
-
# Thread.handle_interrupt(RuntimeError => :on_blocking){
|
793
|
-
# while true
|
794
|
-
# ...
|
795
|
-
# # reach safe point to invoke interrupt
|
796
|
-
# if Thread.pending_interrupt?
|
797
|
-
# Thread.handle_interrupt(Object => :immediate){}
|
798
|
-
# end
|
799
|
-
# ...
|
800
|
-
# end
|
801
|
-
# }
|
802
|
-
# }
|
803
|
-
# ...
|
804
|
-
# th.raise # stop thread
|
805
|
-
#
|
806
|
-
# This example can also be written as the following, which you should use
|
807
|
-
# to avoid asynchronous interrupts.
|
808
|
-
#
|
809
|
-
# flag = true
|
810
|
-
# th = Thread.new{
|
811
|
-
# Thread.handle_interrupt(RuntimeError => :on_blocking){
|
812
|
-
# while true
|
813
|
-
# ...
|
814
|
-
# # reach safe point to invoke interrupt
|
815
|
-
# break if flag == false
|
816
|
-
# ...
|
817
|
-
# end
|
818
|
-
# }
|
819
|
-
# }
|
820
|
-
# ...
|
821
|
-
# flag = false # stop thread
|
822
|
-
def self.pending_interrupt?: (*untyped args) -> bool
|
823
|
-
|
824
|
-
def self.report_on_exception: () -> untyped
|
825
|
-
|
826
|
-
def self.report_on_exception=: (untyped report_on_exception) -> untyped
|
827
|
-
|
828
|
-
# Basically the same as [::new](Thread.downloaded.ruby_doc#method-c-new).
|
829
|
-
# However, if class [Thread](Thread.downloaded.ruby_doc) is subclassed,
|
830
|
-
# then calling `start` in that subclass will not invoke the subclass’s
|
831
|
-
# `initialize` method.
|
832
|
-
def self.start: (*untyped args) -> untyped
|
833
|
-
|
834
|
-
# Stops execution of the current thread, putting it into a “sleep” state,
|
835
|
-
# and schedules execution of another thread.
|
836
|
-
#
|
837
|
-
# ```ruby
|
838
|
-
# a = Thread.new { print "a"; Thread.stop; print "c" }
|
839
|
-
# sleep 0.1 while a.status!='sleep'
|
840
|
-
# print "b"
|
841
|
-
# a.run
|
842
|
-
# a.join
|
843
|
-
# #=> "abc"
|
844
|
-
# ```
|
845
|
-
def self.`stop`: () -> untyped
|
846
|
-
end
|
847
|
-
|
848
|
-
class Thread::Backtrace < Object
|
849
|
-
end
|
850
|
-
|
851
|
-
class Thread::Backtrace::Location
|
852
|
-
def absolute_path: () -> String?
|
853
|
-
|
854
|
-
def base_label: () -> String?
|
855
|
-
|
856
|
-
def label: () -> String?
|
857
|
-
|
858
|
-
def lineno: () -> Integer
|
859
|
-
|
860
|
-
def path: () -> String?
|
861
|
-
end
|
862
|
-
|
863
|
-
# [ConditionVariable](ConditionVariable) objects
|
864
|
-
# augment class [Mutex](https://ruby-doc.org/core-2.6.3/Mutex.html).
|
865
|
-
# Using condition variables, it is possible to suspend while in the middle
|
866
|
-
# of a critical section until a resource becomes available.
|
867
|
-
#
|
868
|
-
# Example:
|
869
|
-
#
|
870
|
-
# ```ruby
|
871
|
-
# mutex = Mutex.new
|
872
|
-
# resource = ConditionVariable.new
|
873
|
-
#
|
874
|
-
# a = Thread.new {
|
875
|
-
# mutex.synchronize {
|
876
|
-
# # Thread 'a' now needs the resource
|
877
|
-
# resource.wait(mutex)
|
878
|
-
# # 'a' can now have the resource
|
879
|
-
# }
|
880
|
-
# }
|
881
|
-
#
|
882
|
-
# b = Thread.new {
|
883
|
-
# mutex.synchronize {
|
884
|
-
# # Thread 'b' has finished using the resource
|
885
|
-
# resource.signal
|
886
|
-
# }
|
887
|
-
# }
|
888
|
-
# ```
|
889
|
-
class Thread::ConditionVariable < Object
|
890
|
-
# Wakes up all threads waiting for this lock.
|
891
|
-
def broadcast: () -> untyped
|
892
|
-
|
893
|
-
def marshal_dump: () -> untyped
|
894
|
-
|
895
|
-
# Wakes up the first thread in line waiting for this lock.
|
896
|
-
def signal: () -> untyped
|
897
|
-
|
898
|
-
# Releases the lock held in `mutex` and waits; reacquires the lock on
|
899
|
-
# wakeup.
|
900
|
-
#
|
901
|
-
# If `timeout` is given, this method returns after `timeout` seconds
|
902
|
-
# passed, even if no other thread doesn't signal.
|
903
|
-
def wait: (*untyped _) -> untyped
|
904
|
-
end
|
905
|
-
|
906
|
-
# [Mutex](Mutex) implements a simple semaphore that
|
907
|
-
# can be used to coordinate access to shared data from multiple concurrent
|
908
|
-
# threads.
|
909
|
-
#
|
910
|
-
# Example:
|
911
|
-
#
|
912
|
-
# ```ruby
|
913
|
-
# semaphore = Mutex.new
|
914
|
-
#
|
915
|
-
# a = Thread.new {
|
916
|
-
# semaphore.synchronize {
|
917
|
-
# # access shared resource
|
918
|
-
# }
|
919
|
-
# }
|
920
|
-
#
|
921
|
-
# b = Thread.new {
|
922
|
-
# semaphore.synchronize {
|
923
|
-
# # access shared resource
|
924
|
-
# }
|
925
|
-
# }
|
926
|
-
# ```
|
927
|
-
class Thread::Mutex < Object
|
928
|
-
# Attempts to grab the lock and waits if it isn’t available. Raises
|
929
|
-
# `ThreadError` if `mutex` was locked by the current thread.
|
930
|
-
def lock: () -> untyped
|
931
|
-
|
932
|
-
# Returns `true` if this lock is currently held by some thread.
|
933
|
-
def locked?: () -> bool
|
934
|
-
|
935
|
-
# Returns `true` if this lock is currently held by current thread.
|
936
|
-
def owned?: () -> bool
|
937
|
-
|
938
|
-
# Obtains a lock, runs the block, and releases the lock when the block
|
939
|
-
# completes. See the example under `Mutex` .
|
940
|
-
def synchronize: () -> untyped
|
941
|
-
|
942
|
-
# Attempts to obtain the lock and returns immediately. Returns `true` if
|
943
|
-
# the lock was granted.
|
944
|
-
def try_lock: () -> bool
|
945
|
-
|
946
|
-
# Releases the lock. Raises `ThreadError` if `mutex` wasn’t locked by the
|
947
|
-
# current thread.
|
948
|
-
def unlock: () -> untyped
|
949
|
-
end
|
950
|
-
|
951
|
-
# The [Queue](Queue) class implements multi-producer,
|
952
|
-
# multi-consumer queues. It is especially useful in threaded programming
|
953
|
-
# when information must be exchanged safely between multiple threads. The
|
954
|
-
# [Queue](Queue) class implements all the required
|
955
|
-
# locking semantics.
|
956
|
-
#
|
957
|
-
# The class implements FIFO type of queue. In a FIFO queue, the first
|
958
|
-
# tasks added are the first retrieved.
|
959
|
-
#
|
960
|
-
# Example:
|
961
|
-
#
|
962
|
-
# ```ruby
|
963
|
-
# queue = Queue.new
|
964
|
-
#
|
965
|
-
# producer = Thread.new do
|
966
|
-
# 5.times do |i|
|
967
|
-
# sleep rand(i) # simulate expense
|
968
|
-
# queue << i
|
969
|
-
# puts "#{i} produced"
|
970
|
-
# end
|
971
|
-
# end
|
972
|
-
#
|
973
|
-
# consumer = Thread.new do
|
974
|
-
# 5.times do |i|
|
975
|
-
# value = queue.pop
|
976
|
-
# sleep rand(i/2) # simulate expense
|
977
|
-
# puts "consumed #{value}"
|
978
|
-
# end
|
979
|
-
# end
|
980
|
-
#
|
981
|
-
# consumer.join
|
982
|
-
# ```
|
983
|
-
class Thread::Queue < Object
|
984
|
-
# Alias for: [push](Queue.downloaded.ruby_doc#method-i-push)
|
985
|
-
def <<: (untyped obj) -> untyped
|
986
|
-
|
987
|
-
# Removes all objects from the queue.
|
988
|
-
def clear: () -> untyped
|
989
|
-
|
990
|
-
# Closes the queue. A closed queue cannot be re-opened.
|
991
|
-
#
|
992
|
-
# After the call to close completes, the following are true:
|
993
|
-
#
|
994
|
-
# - `closed?` will return true
|
995
|
-
#
|
996
|
-
# - `close` will be ignored.
|
997
|
-
#
|
998
|
-
# - calling enq/push/\<\< will raise a `ClosedQueueError` .
|
999
|
-
#
|
1000
|
-
# - when `empty?` is false, calling deq/pop/shift will return an object
|
1001
|
-
# from the queue as usual.
|
1002
|
-
#
|
1003
|
-
# - when `empty?` is true, deq(false) will not suspend the thread and
|
1004
|
-
# will return nil. deq(true) will raise a `ThreadError` .
|
1005
|
-
#
|
1006
|
-
# [ClosedQueueError](https://ruby-doc.org/core-2.6.3/ClosedQueueError.html)
|
1007
|
-
# is inherited from
|
1008
|
-
# [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html), so
|
1009
|
-
# that you can break loop block.
|
1010
|
-
#
|
1011
|
-
# Example:
|
1012
|
-
#
|
1013
|
-
# q = Queue.new
|
1014
|
-
# Thread.new{
|
1015
|
-
# while e = q.deq # wait for nil to break loop
|
1016
|
-
# # ...
|
1017
|
-
# end
|
1018
|
-
# }
|
1019
|
-
# q.close
|
1020
|
-
def close: () -> untyped
|
1021
|
-
|
1022
|
-
# Returns `true` if the queue is closed.
|
1023
|
-
def closed?: () -> bool
|
1024
|
-
|
1025
|
-
# Alias for: [pop](Queue.downloaded.ruby_doc#method-i-pop)
|
1026
|
-
def deq: (*untyped args) -> untyped
|
1027
|
-
|
1028
|
-
# Returns `true` if the queue is empty.
|
1029
|
-
def empty?: () -> bool
|
1030
|
-
|
1031
|
-
# Alias for: [push](Queue.downloaded.ruby_doc#method-i-push)
|
1032
|
-
def enq: (untyped obj) -> untyped
|
1033
|
-
|
1034
|
-
# Returns the length of the queue.
|
1035
|
-
#
|
1036
|
-
#
|
1037
|
-
#
|
1038
|
-
# Also aliased as: [size](Queue.downloaded.ruby_doc#method-i-size)
|
1039
|
-
def length: () -> Integer
|
1040
|
-
|
1041
|
-
def marshal_dump: () -> untyped
|
1042
|
-
|
1043
|
-
# Returns the number of threads waiting on the queue.
|
1044
|
-
def num_waiting: () -> untyped
|
1045
|
-
|
1046
|
-
# Retrieves data from the queue.
|
1047
|
-
#
|
1048
|
-
# If the queue is empty, the calling thread is suspended until data is
|
1049
|
-
# pushed onto the queue. If `non_block` is true, the thread isn't
|
1050
|
-
# suspended, and `ThreadError` is raised.
|
1051
|
-
#
|
1052
|
-
#
|
1053
|
-
#
|
1054
|
-
# Also aliased as: [deq](Queue.downloaded.ruby_doc#method-i-deq),
|
1055
|
-
# [shift](Queue.downloaded.ruby_doc#method-i-shift)
|
1056
|
-
def pop: (*untyped args) -> untyped
|
1057
|
-
|
1058
|
-
# Pushes the given `object` to the queue.
|
1059
|
-
#
|
1060
|
-
#
|
1061
|
-
#
|
1062
|
-
# Also aliased as: [enq](Queue.downloaded.ruby_doc#method-i-enq),
|
1063
|
-
# [\<\<](Queue.downloaded.ruby_doc#method-i-3C-3C)
|
1064
|
-
def push: (untyped obj) -> untyped
|
1065
|
-
|
1066
|
-
# Alias for: [pop](Queue.downloaded.ruby_doc#method-i-pop)
|
1067
|
-
def shift: (*untyped args) -> untyped
|
1068
|
-
|
1069
|
-
# Alias for: [length](Queue.downloaded.ruby_doc#method-i-length)
|
1070
|
-
def size: () -> Integer
|
1071
|
-
end
|
1072
|
-
|
1073
|
-
# This class represents queues of specified size capacity. The push
|
1074
|
-
# operation may be blocked if the capacity is full.
|
1075
|
-
#
|
1076
|
-
# See [Queue](https://ruby-doc.org/core-2.6.3/Queue.html) for an example
|
1077
|
-
# of how a [SizedQueue](SizedQueue) works.
|
1078
|
-
class Thread::SizedQueue < Thread::Queue
|
1079
|
-
# Alias for: [push](SizedQueue.downloaded.ruby_doc#method-i-push)
|
1080
|
-
def <<: (*untyped args) -> untyped
|
1081
|
-
|
1082
|
-
# Alias for: [push](SizedQueue.downloaded.ruby_doc#method-i-push)
|
1083
|
-
def enq: (*untyped args) -> untyped
|
1084
|
-
|
1085
|
-
def initialize: (untyped max) -> SizedQueue
|
1086
|
-
|
1087
|
-
# Returns the maximum size of the queue.
|
1088
|
-
def max: () -> Integer
|
1089
|
-
|
1090
|
-
# Sets the maximum size of the queue to the given `number` .
|
1091
|
-
def max=: (Integer max) -> untyped
|
1092
|
-
|
1093
|
-
# Pushes `object` to the queue.
|
1094
|
-
#
|
1095
|
-
# If there is no space left in the queue, waits until space becomes
|
1096
|
-
# available, unless `non_block` is true. If `non_block` is true, the
|
1097
|
-
# thread isn't suspended, and `ThreadError` is raised.
|
1098
|
-
#
|
1099
|
-
#
|
1100
|
-
#
|
1101
|
-
# Also aliased as: [enq](SizedQueue.downloaded.ruby_doc#method-i-enq),
|
1102
|
-
# [\<\<](SizedQueue.downloaded.ruby_doc#method-i-3C-3C)
|
1103
|
-
def push: (*untyped args) -> untyped
|
1104
|
-
end
|
1105
|
-
|
1106
|
-
ConditionVariable: untyped
|
1107
|
-
|
1108
|
-
Mutex: untyped
|
1109
|
-
|
1110
|
-
Queue: untyped
|
1111
|
-
|
1112
|
-
SizedQueue: untyped
|