rbs 3.10.0 → 3.10.1
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/.github/workflows/c-check.yml +1 -1
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +7 -8
- data/CHANGELOG.md +11 -0
- data/core/array.rbs +5 -9
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +8 -4
- data/core/dir.rbs +2 -2
- data/core/enumerator.rbs +25 -0
- data/core/fiber.rbs +24 -16
- data/core/file.rbs +22 -7
- data/core/float.rbs +15 -11
- data/core/hash.rbs +5 -6
- data/core/integer.rbs +26 -25
- data/core/io/buffer.rbs +3 -3
- data/core/kernel.rbs +4 -0
- data/core/method.rbs +49 -19
- data/core/module.rbs +18 -11
- data/core/numeric.rbs +9 -1
- data/core/pathname.rbs +0 -34
- data/core/proc.rbs +15 -16
- data/core/ractor.rbs +155 -144
- data/core/rational.rbs +19 -10
- data/core/set.rbs +2 -2
- data/core/signal.rbs +24 -14
- data/core/string.rbs +34 -30
- data/core/symbol.rbs +13 -7
- data/core/thread.rbs +3 -4
- data/lib/rbs/collection/config/lockfile_generator.rb +7 -0
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/stdlib/cgi/0/core.rbs +11 -1
- data/stdlib/cgi-escape/0/escape.rbs +33 -15
- data/stdlib/pathname/0/pathname.rbs +36 -0
- metadata +3 -2
data/core/ractor.rbs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# <!-- rdoc-file=ractor.rb -->
|
|
2
|
-
# Ractor.new
|
|
2
|
+
# Ractor.new creates a new Ractor, which can run in parallel with other ractors.
|
|
3
3
|
#
|
|
4
4
|
# # The simplest ractor
|
|
5
5
|
# r = Ractor.new {puts "I am in Ractor!"}
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
# to this: across ractors, thread-safety concerns such as data-races and
|
|
11
11
|
# race-conditions are not possible. The other benefit is parallelism.
|
|
12
12
|
#
|
|
13
|
-
# To achieve this, object sharing is limited across ractors.
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
13
|
+
# To achieve this, object sharing is limited across ractors. Unlike in threads,
|
|
14
|
+
# ractors can't access all the objects available in other ractors. For example,
|
|
15
|
+
# objects normally available through variables in the outer scope are prohibited
|
|
16
|
+
# from being used across ractors.
|
|
17
17
|
#
|
|
18
18
|
# a = 1
|
|
19
19
|
# r = Ractor.new {puts "I am in Ractor! a=#{a}"}
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
# a = 1
|
|
25
25
|
# r = Ractor.new(a) { |a1| puts "I am in Ractor! a=#{a1}"}
|
|
26
26
|
#
|
|
27
|
-
# On CRuby (the default implementation), Global Virtual Machine Lock (GVL)
|
|
28
|
-
# held per ractor, so ractors can
|
|
29
|
-
#
|
|
27
|
+
# On CRuby (the default implementation), the Global Virtual Machine Lock (GVL)
|
|
28
|
+
# is held per ractor, so ractors can run in parallel. This is unlike the
|
|
29
|
+
# situation with threads on CRuby.
|
|
30
30
|
#
|
|
31
31
|
# Instead of accessing shared state, objects should be passed to and from
|
|
32
32
|
# ractors by sending and receiving them as messages.
|
|
33
33
|
#
|
|
34
34
|
# a = 1
|
|
35
35
|
# r = Ractor.new do
|
|
36
|
-
# a_in_ractor = receive # receive blocks until
|
|
36
|
+
# a_in_ractor = receive # receive blocks the Thread until our default port gets sent a message
|
|
37
37
|
# puts "I am in Ractor! a=#{a_in_ractor}"
|
|
38
38
|
# end
|
|
39
39
|
# r.send(a) # pass it
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
#
|
|
47
47
|
# ## Shareable and unshareable objects
|
|
48
48
|
#
|
|
49
|
-
# When an object is sent to
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
49
|
+
# When an object is sent to a ractor, it's important to understand whether the
|
|
50
|
+
# object is shareable or unshareable. Most Ruby objects are unshareable objects.
|
|
51
|
+
# Even frozen objects can be unshareable if they contain (through their instance
|
|
52
|
+
# variables) unfrozen objects.
|
|
53
53
|
#
|
|
54
|
-
# Shareable objects are those which can be used by several
|
|
55
|
-
# compromising thread-safety, for example numbers, `true` and `false`.
|
|
54
|
+
# Shareable objects are those which can be used by several ractors at once
|
|
55
|
+
# without compromising thread-safety, for example numbers, `true` and `false`.
|
|
56
56
|
# Ractor.shareable? allows you to check this, and Ractor.make_shareable tries to
|
|
57
|
-
# make the object shareable if it's not already
|
|
57
|
+
# make the object shareable if it's not already and gives an error if it can't
|
|
58
58
|
# do it.
|
|
59
59
|
#
|
|
60
60
|
# Ractor.shareable?(1) #=> true -- numbers and other immutable basic values are shareable
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
# ary[0].frozen? #=> true
|
|
71
71
|
# ary[1].frozen? #=> true
|
|
72
72
|
#
|
|
73
|
-
# When a shareable object is sent
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
# the
|
|
77
|
-
#
|
|
73
|
+
# When a shareable object is sent via #send, no additional processing occurs on
|
|
74
|
+
# it and it becomes usable by both ractors. When an unshareable object is sent,
|
|
75
|
+
# it can be either *copied* or *moved*. Copying is the default, and it copies
|
|
76
|
+
# the object fully by deep cloning (Object#clone) the non-shareable parts of its
|
|
77
|
+
# structure.
|
|
78
78
|
#
|
|
79
|
-
# data = ['foo', 'bar'.freeze]
|
|
79
|
+
# data = ['foo'.dup, 'bar'.freeze]
|
|
80
80
|
# r = Ractor.new do
|
|
81
81
|
# data2 = Ractor.receive
|
|
82
82
|
# puts "In ractor: #{data2.object_id}, #{data2[0].object_id}, #{data2[1].object_id}"
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
#
|
|
88
88
|
# This will output something like:
|
|
89
89
|
#
|
|
90
|
-
# In ractor:
|
|
91
|
-
# Outside :
|
|
90
|
+
# In ractor: 8, 16, 24
|
|
91
|
+
# Outside : 32, 40, 24
|
|
92
92
|
#
|
|
93
93
|
# Note that the object ids of the array and the non-frozen string inside the
|
|
94
94
|
# array have changed in the ractor because they are different objects. The
|
|
@@ -115,14 +115,14 @@
|
|
|
115
115
|
# Outside: moved? true
|
|
116
116
|
# test.rb:9:in `method_missing': can not send any methods to a moved object (Ractor::MovedError)
|
|
117
117
|
#
|
|
118
|
-
# Notice that even `inspect`
|
|
118
|
+
# Notice that even `inspect` and more basic methods like `__id__` are
|
|
119
119
|
# inaccessible on a moved object.
|
|
120
120
|
#
|
|
121
|
-
# `Class` and `Module` objects are shareable
|
|
122
|
-
# shared between ractors. Ractor objects are also shareable. All operations
|
|
123
|
-
# shareable objects are thread-safe
|
|
124
|
-
#
|
|
125
|
-
#
|
|
121
|
+
# `Class` and `Module` objects are shareable and their class/module definitions
|
|
122
|
+
# are shared between ractors. Ractor objects are also shareable. All operations
|
|
123
|
+
# on shareable objects are thread-safe across ractors. Defining mutable,
|
|
124
|
+
# shareable objects in Ruby is not possible, but C extensions can introduce
|
|
125
|
+
# them.
|
|
126
126
|
#
|
|
127
127
|
# It is prohibited to access (get) instance variables of shareable objects in
|
|
128
128
|
# other ractors if the values of the variables aren't shareable. This can occur
|
|
@@ -189,14 +189,15 @@
|
|
|
189
189
|
# ## Note on code examples
|
|
190
190
|
#
|
|
191
191
|
# In the examples below, sometimes we use the following method to wait for
|
|
192
|
-
# ractors
|
|
192
|
+
# ractors to make progress or finish.
|
|
193
193
|
#
|
|
194
194
|
# def wait
|
|
195
195
|
# sleep(0.1)
|
|
196
196
|
# end
|
|
197
197
|
#
|
|
198
|
-
#
|
|
199
|
-
# code. Most of the time, #join is used to wait for ractors to finish
|
|
198
|
+
# This is **only for demonstration purposes** and shouldn't be used in a real
|
|
199
|
+
# code. Most of the time, #join is used to wait for ractors to finish and
|
|
200
|
+
# Ractor.receive is used to wait for messages.
|
|
200
201
|
#
|
|
201
202
|
# ## Reference
|
|
202
203
|
#
|
|
@@ -215,7 +216,7 @@ class Ractor
|
|
|
215
216
|
# rdoc-file=ractor.rb
|
|
216
217
|
# - [](sym)
|
|
217
218
|
# -->
|
|
218
|
-
#
|
|
219
|
+
# Gets a value from ractor-local storage for the current Ractor.
|
|
219
220
|
#
|
|
220
221
|
def self.[]: (Symbol) -> untyped
|
|
221
222
|
|
|
@@ -223,7 +224,7 @@ class Ractor
|
|
|
223
224
|
# rdoc-file=ractor.rb
|
|
224
225
|
# - []=(sym, val)
|
|
225
226
|
# -->
|
|
226
|
-
#
|
|
227
|
+
# Sets a value in ractor-local storage for the current Ractor.
|
|
227
228
|
#
|
|
228
229
|
def self.[]=: (Symbol, untyped) -> untyped
|
|
229
230
|
|
|
@@ -231,7 +232,7 @@ class Ractor
|
|
|
231
232
|
# rdoc-file=ractor.rb
|
|
232
233
|
# - count()
|
|
233
234
|
# -->
|
|
234
|
-
# Returns the number of
|
|
235
|
+
# Returns the number of ractors currently running or blocking (waiting).
|
|
235
236
|
#
|
|
236
237
|
# Ractor.count #=> 1
|
|
237
238
|
# r = Ractor.new(name: 'example') { Ractor.receive }
|
|
@@ -256,7 +257,7 @@ class Ractor
|
|
|
256
257
|
# rdoc-file=ractor.rb
|
|
257
258
|
# - main()
|
|
258
259
|
# -->
|
|
259
|
-
#
|
|
260
|
+
# Returns the main ractor.
|
|
260
261
|
#
|
|
261
262
|
def self.main: () -> Ractor
|
|
262
263
|
|
|
@@ -264,7 +265,7 @@ class Ractor
|
|
|
264
265
|
# rdoc-file=ractor.rb
|
|
265
266
|
# - main?()
|
|
266
267
|
# -->
|
|
267
|
-
#
|
|
268
|
+
# Returns true if the current ractor is the main ractor.
|
|
268
269
|
#
|
|
269
270
|
def self.main?: () -> boolish
|
|
270
271
|
|
|
@@ -272,7 +273,7 @@ class Ractor
|
|
|
272
273
|
# rdoc-file=ractor.rb
|
|
273
274
|
# - Ractor.make_shareable(obj, copy: false) -> shareable_obj
|
|
274
275
|
# -->
|
|
275
|
-
#
|
|
276
|
+
# Makes `obj` shareable between ractors.
|
|
276
277
|
#
|
|
277
278
|
# `obj` and all the objects it refers to will be frozen, unless they are already
|
|
278
279
|
# shareable.
|
|
@@ -311,10 +312,10 @@ class Ractor
|
|
|
311
312
|
# rdoc-file=ractor.rb
|
|
312
313
|
# - Ractor.new(*args, name: nil) {|*args| block } -> ractor
|
|
313
314
|
# -->
|
|
314
|
-
#
|
|
315
|
+
# Creates a new Ractor with args and a block.
|
|
315
316
|
#
|
|
316
|
-
# The given block (Proc)
|
|
317
|
-
#
|
|
317
|
+
# The given block (Proc) is isolated (can't access any outer variables). `self`
|
|
318
|
+
# inside the block will refer to the current Ractor.
|
|
318
319
|
#
|
|
319
320
|
# r = Ractor.new { puts "Hi, I am #{self.inspect}" }
|
|
320
321
|
# r.join
|
|
@@ -346,7 +347,7 @@ class Ractor
|
|
|
346
347
|
# rdoc-file=ractor.rb
|
|
347
348
|
# - Ractor.receive -> obj
|
|
348
349
|
# -->
|
|
349
|
-
#
|
|
350
|
+
# Receives a message from the current ractor's default port.
|
|
350
351
|
#
|
|
351
352
|
def self.receive: () -> untyped
|
|
352
353
|
|
|
@@ -359,9 +360,48 @@ class Ractor
|
|
|
359
360
|
|
|
360
361
|
# <!--
|
|
361
362
|
# rdoc-file=ractor.rb
|
|
362
|
-
# - Ractor.select(*
|
|
363
|
+
# - Ractor.select(*ractors_or_ports) -> [ractor or port, obj]
|
|
363
364
|
# -->
|
|
364
|
-
#
|
|
365
|
+
# Blocks the current Thread until one of the given ports has received a message.
|
|
366
|
+
# Returns an array of two elements where the first element is the Port and the
|
|
367
|
+
# second is the received object. This method can also accept Ractor objects
|
|
368
|
+
# themselves, and in that case will wait until one has terminated and return a
|
|
369
|
+
# two-element array where the first element is the ractor and the second is its
|
|
370
|
+
# termination value.
|
|
371
|
+
#
|
|
372
|
+
# p1, p2 = Ractor::Port.new, Ractor::Port.new
|
|
373
|
+
# ps = [p1, p2]
|
|
374
|
+
# rs = 2.times.map do |i|
|
|
375
|
+
# Ractor.new(ps.shift, i) do |p, i|
|
|
376
|
+
# sleep rand(0.99)
|
|
377
|
+
# p.send("r#{i}")
|
|
378
|
+
# sleep rand(0.99)
|
|
379
|
+
# "r#{i} done"
|
|
380
|
+
# end
|
|
381
|
+
# end
|
|
382
|
+
#
|
|
383
|
+
# waiting_on = [p1, p2, *rs]
|
|
384
|
+
# until waiting_on.empty?
|
|
385
|
+
# received_on, obj = Ractor.select(*waiting_on)
|
|
386
|
+
# waiting_on.delete(received_on)
|
|
387
|
+
# puts obj
|
|
388
|
+
# end
|
|
389
|
+
#
|
|
390
|
+
# # r0
|
|
391
|
+
# # r1
|
|
392
|
+
# # r1 done
|
|
393
|
+
# # r0 done
|
|
394
|
+
#
|
|
395
|
+
# The following example is almost equivalent to `ractors.map(&:value)` except
|
|
396
|
+
# the thread is unblocked when any of the ractors has terminated as opposed to
|
|
397
|
+
# waiting for their termination in the array element order.
|
|
398
|
+
#
|
|
399
|
+
# values = []
|
|
400
|
+
# until ractors.empty?
|
|
401
|
+
# r, val = Ractor.select(*ractors)
|
|
402
|
+
# ractors.delete(r)
|
|
403
|
+
# values << val
|
|
404
|
+
# end
|
|
365
405
|
#
|
|
366
406
|
def self.select: (?) -> Array[untyped]
|
|
367
407
|
|
|
@@ -371,7 +411,7 @@ class Ractor
|
|
|
371
411
|
# -->
|
|
372
412
|
# Checks if the object is shareable by ractors.
|
|
373
413
|
#
|
|
374
|
-
# Ractor.shareable?(1) #=> true -- numbers
|
|
414
|
+
# Ractor.shareable?(1) #=> true -- numbers are shareable
|
|
375
415
|
# Ractor.shareable?('foo') #=> false, unless the string is frozen due to # frozen_string_literal: true
|
|
376
416
|
# Ractor.shareable?('foo'.freeze) #=> true
|
|
377
417
|
#
|
|
@@ -384,16 +424,17 @@ class Ractor
|
|
|
384
424
|
# rdoc-file=ractor.rb
|
|
385
425
|
# - Ractor.shareable_proc(self: nil){} -> shareable proc
|
|
386
426
|
# -->
|
|
387
|
-
#
|
|
388
|
-
#
|
|
427
|
+
# Returns a shareable copy of the given block's Proc. The value of `self` in the
|
|
428
|
+
# Proc will be replaced with the value passed via the `self:` keyword, or `nil`
|
|
429
|
+
# if not given.
|
|
389
430
|
#
|
|
390
|
-
# In a shareable Proc,
|
|
431
|
+
# In a shareable Proc, access to any outer variables if prohibited.
|
|
391
432
|
#
|
|
392
433
|
# a = 42
|
|
393
434
|
# Ractor.shareable_proc{ p a }
|
|
394
435
|
# #=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError)
|
|
395
436
|
#
|
|
396
|
-
# The `self`
|
|
437
|
+
# The value of `self` in the Proc must be a shareable object.
|
|
397
438
|
#
|
|
398
439
|
# Ractor.shareable_proc(self: self){}
|
|
399
440
|
# #=> self should be shareable: main (Ractor::IsolationError)
|
|
@@ -403,9 +444,9 @@ class Ractor
|
|
|
403
444
|
|
|
404
445
|
# <!--
|
|
405
446
|
# rdoc-file=ractor.rb
|
|
406
|
-
# - Ractor.
|
|
447
|
+
# - Ractor.shareable_lambda(self: nil){} -> shareable lambda
|
|
407
448
|
# -->
|
|
408
|
-
# Same as Ractor.shareable_proc, but returns lambda
|
|
449
|
+
# Same as Ractor.shareable_proc, but returns a lambda Proc.
|
|
409
450
|
#
|
|
410
451
|
def self.shareable_lambda: [T] () { (?) [self: nil] -> T } -> ^(?) [self: nil] -> T
|
|
411
452
|
| [T, S] (self: S) { (?) [self: S] -> T } -> ^(?) [self: S] -> T
|
|
@@ -414,9 +455,9 @@ class Ractor
|
|
|
414
455
|
# rdoc-file=ractor.rb
|
|
415
456
|
# - Ractor.store_if_absent(key){ init_block }
|
|
416
457
|
# -->
|
|
417
|
-
# If the corresponding value is not set,
|
|
418
|
-
# the value in thread-safe manner. This method returns
|
|
419
|
-
# value.
|
|
458
|
+
# If the corresponding ractor-local value is not set, yields a value with
|
|
459
|
+
# init_block and stores the value in a thread-safe manner. This method returns
|
|
460
|
+
# the stored value.
|
|
420
461
|
#
|
|
421
462
|
# (1..10).map{
|
|
422
463
|
# Thread.new(it){|i|
|
|
@@ -438,7 +479,7 @@ class Ractor
|
|
|
438
479
|
# rdoc-file=ractor.rb
|
|
439
480
|
# - [](sym)
|
|
440
481
|
# -->
|
|
441
|
-
#
|
|
482
|
+
# Gets a value from ractor-local storage for the current Ractor. Obsolete, use
|
|
442
483
|
# Ractor.[] instead.
|
|
443
484
|
#
|
|
444
485
|
%a{deprecated: Use Ractor.[] instead}
|
|
@@ -448,7 +489,7 @@ class Ractor
|
|
|
448
489
|
# rdoc-file=ractor.rb
|
|
449
490
|
# - []=(sym, val)
|
|
450
491
|
# -->
|
|
451
|
-
#
|
|
492
|
+
# Sets a value in ractor-local storage for the current Ractor. Obsolete, use
|
|
452
493
|
# Ractor.[]= instead.
|
|
453
494
|
#
|
|
454
495
|
%a{deprecated: Use Ractor.[]= instead}
|
|
@@ -458,7 +499,7 @@ class Ractor
|
|
|
458
499
|
# rdoc-file=ractor.rb
|
|
459
500
|
# - ractor.default_port -> port object
|
|
460
501
|
# -->
|
|
461
|
-
#
|
|
502
|
+
# Returns the default port of the Ractor.
|
|
462
503
|
#
|
|
463
504
|
def default_port: () -> Port[untyped]
|
|
464
505
|
|
|
@@ -473,13 +514,13 @@ class Ractor
|
|
|
473
514
|
# rdoc-file=ractor.rb
|
|
474
515
|
# - ractor.join -> self
|
|
475
516
|
# -->
|
|
476
|
-
#
|
|
477
|
-
#
|
|
517
|
+
# Waits for the termination of the Ractor. If the Ractor was aborted (terminated
|
|
518
|
+
# by an unhandled exception), the exception is raised in the current ractor.
|
|
478
519
|
#
|
|
479
520
|
# Ractor.new{}.join #=> ractor
|
|
480
521
|
#
|
|
481
522
|
# Ractor.new{ raise "foo" }.join
|
|
482
|
-
# #=>
|
|
523
|
+
# #=> raises the exception "foo (RuntimeError)"
|
|
483
524
|
#
|
|
484
525
|
def join: () -> self
|
|
485
526
|
|
|
@@ -487,7 +528,7 @@ class Ractor
|
|
|
487
528
|
# rdoc-file=ractor.rb
|
|
488
529
|
# - name()
|
|
489
530
|
# -->
|
|
490
|
-
#
|
|
531
|
+
# Returns the name set in Ractor.new, or `nil`.
|
|
491
532
|
#
|
|
492
533
|
def name: () -> String?
|
|
493
534
|
|
|
@@ -495,26 +536,27 @@ class Ractor
|
|
|
495
536
|
# rdoc-file=ractor.rb
|
|
496
537
|
# - ractor.monitor(port) -> self
|
|
497
538
|
# -->
|
|
498
|
-
#
|
|
499
|
-
#
|
|
500
|
-
#
|
|
501
|
-
# exception.
|
|
539
|
+
# Registers the port as a monitoring port for this ractor. When the ractor
|
|
540
|
+
# terminates, the port receives a Symbol object.
|
|
541
|
+
#
|
|
542
|
+
# * `:exited` is sent if the ractor terminates without an unhandled exception.
|
|
543
|
+
# * `:aborted` is sent if the ractor terminates by an unhandled exception.
|
|
502
544
|
#
|
|
503
|
-
#
|
|
504
|
-
#
|
|
505
|
-
#
|
|
545
|
+
# r = Ractor.new{ some_task() }
|
|
546
|
+
# r.monitor(port = Ractor::Port.new)
|
|
547
|
+
# port.receive #=> :exited and r is terminated
|
|
506
548
|
#
|
|
507
|
-
#
|
|
508
|
-
#
|
|
509
|
-
#
|
|
549
|
+
# r = Ractor.new{ raise "foo" }
|
|
550
|
+
# r.monitor(port = Ractor::Port.new)
|
|
551
|
+
# port.receive #=> :aborted and r is terminated by the RuntimeError "foo"
|
|
510
552
|
#
|
|
511
553
|
def monitor: [T < Symbol] (Port[T]) -> untyped
|
|
512
554
|
|
|
513
555
|
# <!--
|
|
514
556
|
# rdoc-file=ractor.rb
|
|
515
|
-
# - ractor.send(msg) -> self
|
|
557
|
+
# - ractor.send(msg, move: false) -> self
|
|
516
558
|
# -->
|
|
517
|
-
#
|
|
559
|
+
# This is equivalent to Port#send to the ractor's #default_port.
|
|
518
560
|
#
|
|
519
561
|
def send: (untyped obj, ?move: boolish) -> Ractor
|
|
520
562
|
|
|
@@ -529,7 +571,7 @@ class Ractor
|
|
|
529
571
|
# rdoc-file=ractor.rb
|
|
530
572
|
# - ractor.unmonitor(port) -> self
|
|
531
573
|
# -->
|
|
532
|
-
#
|
|
574
|
+
# Unregisters the port from the monitoring ports for this ractor.
|
|
533
575
|
#
|
|
534
576
|
def unmonitor: (Port[untyped]) -> self
|
|
535
577
|
|
|
@@ -537,9 +579,10 @@ class Ractor
|
|
|
537
579
|
# rdoc-file=ractor.rb
|
|
538
580
|
# - ractor.value -> obj
|
|
539
581
|
# -->
|
|
540
|
-
# Waits for `ractor` to complete
|
|
541
|
-
#
|
|
542
|
-
#
|
|
582
|
+
# Waits for `ractor` to complete and returns its value or raises the exception
|
|
583
|
+
# which terminated the Ractor. The termination value will be moved to the
|
|
584
|
+
# calling Ractor. Therefore, at most 1 Ractor can receive another ractor's
|
|
585
|
+
# termination value.
|
|
543
586
|
#
|
|
544
587
|
# r = Ractor.new{ [1, 2] }
|
|
545
588
|
# r.value #=> [1, 2] (unshareable object)
|
|
@@ -576,36 +619,16 @@ class Ractor
|
|
|
576
619
|
# <!-- rdoc-file=ractor.c -->
|
|
577
620
|
# Raised when an attempt is made to send a message to a closed port, or to
|
|
578
621
|
# retrieve a message from a closed and empty port. Ports may be closed
|
|
579
|
-
# explicitly with Ractor#
|
|
580
|
-
#
|
|
581
|
-
#
|
|
582
|
-
# r = Ractor.new { sleep(500) }
|
|
583
|
-
# r.close_outgoing
|
|
584
|
-
# r.take # Ractor::ClosedError
|
|
585
|
-
#
|
|
586
|
-
# ClosedError is a descendant of StopIteration, so the closing of the ractor
|
|
587
|
-
# will break the loops without propagating the error:
|
|
622
|
+
# explicitly with Ractor::Port#close and are closed implicitly when a Ractor
|
|
623
|
+
# terminates.
|
|
588
624
|
#
|
|
589
|
-
#
|
|
590
|
-
#
|
|
591
|
-
#
|
|
592
|
-
#
|
|
593
|
-
# end
|
|
594
|
-
# puts "loop exited"
|
|
595
|
-
# end
|
|
596
|
-
#
|
|
597
|
-
# 3.times{|i| r << i}
|
|
598
|
-
# r.close_incoming
|
|
599
|
-
# r.take
|
|
600
|
-
# puts "Continue successfully"
|
|
625
|
+
# port = Ractor::Port.new
|
|
626
|
+
# port.close
|
|
627
|
+
# port << "test" # Ractor::ClosedError
|
|
628
|
+
# port.receive # Ractor::ClosedError
|
|
601
629
|
#
|
|
602
|
-
#
|
|
603
|
-
#
|
|
604
|
-
# Received: 0
|
|
605
|
-
# Received: 1
|
|
606
|
-
# Received: 2
|
|
607
|
-
# loop exited
|
|
608
|
-
# Continue successfully
|
|
630
|
+
# ClosedError is a descendant of StopIteration, so the closing of a port will
|
|
631
|
+
# break out of loops without propagating the error.
|
|
609
632
|
#
|
|
610
633
|
class ClosedError < StopIteration
|
|
611
634
|
end
|
|
@@ -624,7 +647,7 @@ class Ractor
|
|
|
624
647
|
|
|
625
648
|
# <!-- rdoc-file=ractor.c -->
|
|
626
649
|
# Raised on an attempt to access an object which was moved in Ractor#send or
|
|
627
|
-
# Ractor.
|
|
650
|
+
# Ractor::Port#send.
|
|
628
651
|
#
|
|
629
652
|
# r = Ractor.new { sleep }
|
|
630
653
|
#
|
|
@@ -638,7 +661,7 @@ class Ractor
|
|
|
638
661
|
|
|
639
662
|
# <!-- rdoc-file=ractor.c -->
|
|
640
663
|
# A special object which replaces any value that was moved to another ractor in
|
|
641
|
-
# Ractor#send or Ractor.
|
|
664
|
+
# Ractor#send or Ractor::Port#send. Any attempt to access the object results in
|
|
642
665
|
# Ractor::MovedError.
|
|
643
666
|
#
|
|
644
667
|
# r = Ractor.new { receive }
|
|
@@ -730,22 +753,10 @@ class Ractor
|
|
|
730
753
|
# rdoc-file=ractor.rb
|
|
731
754
|
# - port.close
|
|
732
755
|
# -->
|
|
733
|
-
#
|
|
734
|
-
#
|
|
756
|
+
# Closes the port. Sending to a closed port is prohibited. Receiving is also
|
|
757
|
+
# prohibited if there are no messages in its message queue.
|
|
735
758
|
#
|
|
736
|
-
#
|
|
737
|
-
# Ractor.new port do |port|
|
|
738
|
-
# port.send 1 # OK
|
|
739
|
-
# port.send 2 # OK
|
|
740
|
-
# port.close
|
|
741
|
-
# port.send 3 # raise Ractor::ClosedError
|
|
742
|
-
# end
|
|
743
|
-
#
|
|
744
|
-
# port.receive #=> 1
|
|
745
|
-
# port.receive #=> 2
|
|
746
|
-
# port.receive #=> raise Ractor::ClosedError
|
|
747
|
-
#
|
|
748
|
-
# Now, only a Ractor which creates the port is allowed to close ports.
|
|
759
|
+
# Only the Ractor which created the port is allowed to close it.
|
|
749
760
|
#
|
|
750
761
|
# port = Ractor::Port.new
|
|
751
762
|
# Ractor.new port do |port|
|
|
@@ -758,7 +769,7 @@ class Ractor
|
|
|
758
769
|
# rdoc-file=ractor.rb
|
|
759
770
|
# - port.closed? -> true/false
|
|
760
771
|
# -->
|
|
761
|
-
#
|
|
772
|
+
# Returns whether or not the port is closed.
|
|
762
773
|
#
|
|
763
774
|
def closed?: () -> bool
|
|
764
775
|
|
|
@@ -773,7 +784,8 @@ class Ractor
|
|
|
773
784
|
# rdoc-file=ractor.rb
|
|
774
785
|
# - port.receive -> msg
|
|
775
786
|
# -->
|
|
776
|
-
#
|
|
787
|
+
# Receives a message from the port (which was sent there by Port#send). Only the
|
|
788
|
+
# ractor that created the port can receive messages this way.
|
|
777
789
|
#
|
|
778
790
|
# port = Ractor::Port.new
|
|
779
791
|
# r = Ractor.new port do |port|
|
|
@@ -783,9 +795,9 @@ class Ractor
|
|
|
783
795
|
# v1 = port.receive
|
|
784
796
|
# puts "Received: #{v1}"
|
|
785
797
|
# r.join
|
|
786
|
-
# #
|
|
798
|
+
# # This will print: "Received: message1"
|
|
787
799
|
#
|
|
788
|
-
# The method blocks if the message queue is empty.
|
|
800
|
+
# The method blocks the current Thread if the message queue is empty.
|
|
789
801
|
#
|
|
790
802
|
# port = Ractor::Port.new
|
|
791
803
|
# r = Ractor.new port do |port|
|
|
@@ -811,8 +823,8 @@ class Ractor
|
|
|
811
823
|
# Still received only one
|
|
812
824
|
# Received: message2
|
|
813
825
|
#
|
|
814
|
-
# If
|
|
815
|
-
# Ractor::ClosedError
|
|
826
|
+
# If the port is closed and there are no more messages in the message queue, the
|
|
827
|
+
# method raises Ractor::ClosedError.
|
|
816
828
|
#
|
|
817
829
|
# port = Ractor::Port.new
|
|
818
830
|
# port.close
|
|
@@ -824,28 +836,27 @@ class Ractor
|
|
|
824
836
|
# rdoc-file=ractor.rb
|
|
825
837
|
# - port.send(msg, move: false) -> self
|
|
826
838
|
# -->
|
|
827
|
-
#
|
|
839
|
+
# Sends a message to the port to be accepted by port.receive.
|
|
828
840
|
#
|
|
829
841
|
# port = Ractor::Port.new
|
|
830
|
-
# r = Ractor.new do
|
|
831
|
-
#
|
|
842
|
+
# r = Ractor.new(port) do |port|
|
|
843
|
+
# port.send 'message'
|
|
832
844
|
# end
|
|
833
845
|
# value = port.receive
|
|
834
846
|
# puts "Received #{value}"
|
|
835
847
|
# # Prints: "Received: message"
|
|
836
848
|
#
|
|
837
|
-
# The method is non-blocking (will return immediately even if the ractor
|
|
838
|
-
# ready to receive anything):
|
|
849
|
+
# The method is non-blocking (it will return immediately even if the ractor that
|
|
850
|
+
# created the port is not ready to receive anything):
|
|
839
851
|
#
|
|
840
852
|
# port = Ractor::Port.new
|
|
841
853
|
# r = Ractor.new(port) do |port|
|
|
842
|
-
# port.send 'test'
|
|
854
|
+
# port.send 'test'
|
|
843
855
|
# puts "Sent successfully"
|
|
844
856
|
# # Prints: "Sent successfully" immediately
|
|
845
857
|
# end
|
|
846
858
|
#
|
|
847
|
-
# An attempt to send to a
|
|
848
|
-
# Ractor::ClosedError.
|
|
859
|
+
# An attempt to send to a closed port will raise Ractor::ClosedError.
|
|
849
860
|
#
|
|
850
861
|
# r = Ractor.new {Ractor::Port.new}
|
|
851
862
|
# r.join
|
|
@@ -857,8 +868,8 @@ class Ractor
|
|
|
857
868
|
# If the `obj` is unshareable, by default it will be copied into the receiving
|
|
858
869
|
# ractor by deep cloning.
|
|
859
870
|
#
|
|
860
|
-
# If the object is shareable,
|
|
861
|
-
#
|
|
871
|
+
# If the object is shareable, a reference to the object will be sent to the
|
|
872
|
+
# receiving ractor.
|
|
862
873
|
#
|
|
863
874
|
def send: (T obj, ?move: boolish) -> self
|
|
864
875
|
|
|
@@ -876,14 +887,14 @@ class Ractor
|
|
|
876
887
|
end
|
|
877
888
|
|
|
878
889
|
# <!-- rdoc-file=ractor.c -->
|
|
879
|
-
# Raised on
|
|
880
|
-
# Ractor. Its `cause` will contain the original exception, and `ractor` is
|
|
881
|
-
# original ractor it was raised in.
|
|
890
|
+
# Raised on Ractor#join or Ractor#value if there was an uncaught exception in
|
|
891
|
+
# the Ractor. Its `cause` will contain the original exception, and `ractor` is
|
|
892
|
+
# the original ractor it was raised in.
|
|
882
893
|
#
|
|
883
894
|
# r = Ractor.new { raise "Something weird happened" }
|
|
884
895
|
#
|
|
885
896
|
# begin
|
|
886
|
-
# r.
|
|
897
|
+
# r.value
|
|
887
898
|
# rescue => e
|
|
888
899
|
# p e # => #<Ractor::RemoteError: thrown by remote Ractor.>
|
|
889
900
|
# p e.ractor == r # => true
|
|
@@ -892,7 +903,7 @@ class Ractor
|
|
|
892
903
|
#
|
|
893
904
|
class RemoteError < Ractor::Error
|
|
894
905
|
# <!-- rdoc-file=ractor.rb -->
|
|
895
|
-
# The Ractor
|
|
906
|
+
# The Ractor in which the uncaught exception was raised.
|
|
896
907
|
#
|
|
897
908
|
def ractor: () -> Ractor
|
|
898
909
|
end
|
data/core/rational.rbs
CHANGED
|
@@ -157,20 +157,29 @@ class Rational < Numeric
|
|
|
157
157
|
|
|
158
158
|
# <!--
|
|
159
159
|
# rdoc-file=rational.c
|
|
160
|
-
# -
|
|
160
|
+
# - self <=> other -> -1, 0, 1, or nil
|
|
161
161
|
# -->
|
|
162
|
-
#
|
|
163
|
-
# or greater than `numeric`.
|
|
162
|
+
# Compares `self` and `other`.
|
|
164
163
|
#
|
|
165
|
-
#
|
|
164
|
+
# Returns:
|
|
166
165
|
#
|
|
167
|
-
#
|
|
168
|
-
#
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
# Rational(1, 3) <=> 0.3 #=> 1
|
|
166
|
+
# * `-1`, if `self` is less than `other`.
|
|
167
|
+
# * `0`, if the two values are the same.
|
|
168
|
+
# * `1`, if `self` is greater than `other`.
|
|
169
|
+
# * `nil`, if the two values are incomparable.
|
|
172
170
|
#
|
|
173
|
-
#
|
|
171
|
+
# Examples:
|
|
172
|
+
#
|
|
173
|
+
# Rational(2, 3) <=> Rational(4, 3) # => -1
|
|
174
|
+
# Rational(2, 1) <=> Rational(2, 1) # => 0
|
|
175
|
+
# Rational(2, 1) <=> 2 # => 0
|
|
176
|
+
# Rational(2, 1) <=> 2.0 # => 0
|
|
177
|
+
# Rational(2, 1) <=> Complex(2, 0) # => 0
|
|
178
|
+
# Rational(4, 3) <=> Rational(2, 3) # => 1
|
|
179
|
+
# Rational(4, 3) <=> :foo # => nil
|
|
180
|
+
#
|
|
181
|
+
# Class Rational includes module Comparable, each of whose methods uses
|
|
182
|
+
# Rational#<=> for comparison.
|
|
174
183
|
#
|
|
175
184
|
def <=>: (Integer | Rational) -> Integer
|
|
176
185
|
| (untyped) -> Integer?
|