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.
data/core/ractor.rbs CHANGED
@@ -1,5 +1,5 @@
1
1
  # <!-- rdoc-file=ractor.rb -->
2
- # Ractor.new makes a new Ractor, which can run in parallel.
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. For example, unlike
14
- # in threads, ractors can't access all the objects available in other ractors.
15
- # Even objects normally available through variables in the outer scope are
16
- # prohibited from being used across ractors.
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) is
28
- # held per ractor, so ractors can perform in parallel without locking each
29
- # other. This is unlike the situation with threads on CRuby.
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 somebody passes a message
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 and from a ractor, it's important to understand
50
- # whether the object is shareable or unshareable. Most Ruby objects are
51
- # unshareable objects. Even frozen objects can be unshareable if they contain
52
- # (through their instance variables) unfrozen objects.
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 threads without
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, and gives an error if it can't
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 (via #send or Ractor.yield), no additional
74
- # processing occurs on it. It just becomes usable by both ractors. When an
75
- # unshareable object is sent, it can be either *copied* or *moved*. The first is
76
- # the default, and it copies the object fully by deep cloning (Object#clone) the
77
- # non-shareable parts of its structure.
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: 340, 360, 320
91
- # Outside : 380, 400, 320
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` (and more basic methods like `__id__`) is
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 so the class/module definitions are
122
- # shared between ractors. Ractor objects are also shareable. All operations on
123
- # shareable objects are thread-safe, so the thread-safety property will be kept.
124
- # We can not define mutable shareable objects in Ruby, but C extensions can
125
- # introduce them.
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 that are not currently blocked to finish (or to make progress).
192
+ # ractors to make progress or finish.
193
193
  #
194
194
  # def wait
195
195
  # sleep(0.1)
196
196
  # end
197
197
  #
198
- # It 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.
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
- # get a value from ractor-local storage of current Ractor
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
- # set a value in ractor-local storage of current Ractor
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 Ractors currently running or blocking (waiting).
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
- # returns main ractor
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
- # return true if the current ractor is main ractor
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
- # Make `obj` shareable between ractors.
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
- # Create a new Ractor with args and a block.
315
+ # Creates a new Ractor with args and a block.
315
316
  #
316
- # The given block (Proc) will be isolated (can't access any outer variables).
317
- # `self` inside the block will refer to the current Ractor.
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
- # Receive a message from the default port.
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(*ports) -> [...]
363
+ # - Ractor.select(*ractors_or_ports) -> [ractor or port, obj]
363
364
  # -->
364
- # TBD
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 and other immutable basic values are frozen
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
- # It returns shareable Proc object. The Proc object is shareable and the self in
388
- # a block will be replaced with the value passed via `self:` keyword.
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, you can not access to the outer variables.
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` should be a shareable object
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.shareable_proc{} -> shareable proc
447
+ # - Ractor.shareable_lambda(self: nil){} -> shareable lambda
407
448
  # -->
408
- # Same as Ractor.shareable_proc, but returns lambda proc.
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, yield a value with init_block and store
418
- # the value in thread-safe manner. This method returns corresponding stored
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
- # get a value from ractor-local storage for current Ractor Obsolete and use
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
- # set a value in ractor-local storage for current Ractor Obsolete and use
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
- # return default port of the Ractor.
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
- # Wait for the termination of the Ractor. If the Ractor was aborted (terminated
477
- # with an exception), Ractor#value is called to raise an exception.
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
- # #=> raise an exception "foo (RuntimeError)"
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
- # The name set in Ractor.new, or `nil`.
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
- # Register port as a monitoring port. If the ractor terminated, the port
499
- # received a Symbol object. :exited will be sent if the ractor terminated
500
- # without an exception. :aborted will be sent if the ractor terminated with a
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
- # r = Ractor.new{ some_task() }
504
- # r.monitor(port = Ractor::Port.new)
505
- # port.receive #=> :exited and r is terminated
545
+ # r = Ractor.new{ some_task() }
546
+ # r.monitor(port = Ractor::Port.new)
547
+ # port.receive #=> :exited and r is terminated
506
548
  #
507
- # r = Ractor.new{ raise "foo" }
508
- # r.monitor(port = Ractor::Port.new)
509
- # port.receive #=> :terminated and r is terminated with an exception "foo"
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
- # It is equivalent to default_port.send(msg)
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
- # Unregister port from the monitoring ports.
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, using #join, and return its value or raise the
541
- # exception which terminated the Ractor. The value will not be copied even if it
542
- # is unshareable object. Therefore at most 1 Ractor can get a value.
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#close_outgoing/close_incoming and are closed implicitly
580
- # when a Ractor terminates.
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
- # r = Ractor.new do
590
- # loop do
591
- # msg = receive # raises ClosedError and loop traps it
592
- # puts "Received: #{msg}"
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
- # This will print:
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.yield.
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.yield. Any attempt to access the object results in
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
- # Close the port. On the closed port, sending is not prohibited. Receiving is
734
- # also not allowed if there is no sent messages arrived before closing.
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
- # port = Ractor::Port.new
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
- # Return the port is closed or not.
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
- # Receive a message to the port (which was sent there by Port#send).
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
- # # Here will be printed: "Received: message1"
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 close_incoming was called on the ractor, the method raises
815
- # Ractor::ClosedError if there are no more messages in the message queue:
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
- # Send a message to a port to be accepted by port.receive.
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
- # r.send 'message'
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 is not
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 port which already closed its execution will raise
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, it only send a reference to the object without
861
- # cloning.
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 attempt to Ractor#take if there was an uncaught exception in the
880
- # Ractor. Its `cause` will contain the original exception, and `ractor` is the
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.take
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 an uncaught exception is raised in.
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
- # - rational <=> numeric -> -1, 0, +1, or nil
160
+ # - self <=> other -> -1, 0, 1, or nil
161
161
  # -->
162
- # Returns -1, 0, or +1 depending on whether `rational` is less than, equal to,
163
- # or greater than `numeric`.
162
+ # Compares `self` and `other`.
164
163
  #
165
- # `nil` is returned if the two values are incomparable.
164
+ # Returns:
166
165
  #
167
- # Rational(2, 3) <=> Rational(2, 3) #=> 0
168
- # Rational(5) <=> 5 #=> 0
169
- # Rational(2, 3) <=> Rational(1, 3) #=> 1
170
- # Rational(1, 3) <=> 1 #=> -1
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
- # Rational(1, 3) <=> "0.3" #=> nil
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?