@@ -350,68 +350,6 @@ class Ractor
350350 #
351351 def self.receive : () -> untyped
352352
353- # <!--
354- # rdoc-file=ractor.rb
355- # - Ractor.receive_if {|msg| block } -> msg
356- # -->
357- # Receive only a specific message.
358- #
359- # Instead of Ractor.receive, Ractor.receive_if can be given a pattern (or any
360- # filter) in a block and you can choose the messages to accept that are
361- # available in your ractor's incoming queue.
362- #
363- # r = Ractor.new do
364- # p Ractor.receive_if{|msg| msg.match?(/foo/)} #=> "foo3"
365- # p Ractor.receive_if{|msg| msg.match?(/bar/)} #=> "bar1"
366- # p Ractor.receive_if{|msg| msg.match?(/baz/)} #=> "baz2"
367- # end
368- # r << "bar1"
369- # r << "baz2"
370- # r << "foo3"
371- # r.take
372- #
373- # This will output:
374- #
375- # foo3
376- # bar1
377- # baz2
378- #
379- # If the block returns a truthy value, the message is removed from the incoming
380- # queue and returned. Otherwise, the message remains in the incoming queue and
381- # the next messages are checked by the given block.
382- #
383- # If there are no messages left in the incoming queue, the method will block
384- # until new messages arrive.
385- #
386- # If the block is escaped by break/return/exception/throw, the message is
387- # removed from the incoming queue as if a truthy value had been returned.
388- #
389- # r = Ractor.new do
390- # val = Ractor.receive_if{|msg| msg.is_a?(Array)}
391- # puts "Received successfully: #{val}"
392- # end
393- #
394- # r.send(1)
395- # r.send('test')
396- # wait
397- # puts "2 non-matching sent, nothing received"
398- # r.send([1, 2, 3])
399- # wait
400- #
401- # Prints:
402- #
403- # 2 non-matching sent, nothing received
404- # Received successfully: [1, 2, 3]
405- #
406- # Note that you can not call receive/receive_if in the given block recursively.
407- # You should not do any tasks in the block other than message filtration.
408- #
409- # Ractor.current << true
410- # Ractor.receive_if{|msg| Ractor.receive}
411- # #=> `receive': can not call receive/receive_if recursively (Ractor::Error)
412- #
413- def self.receive_if : () { (untyped ) -> boolish } -> untyped
414-
415353 # <!--
416354 # rdoc-file=ractor.rb
417355 # - recv()
@@ -425,7 +363,7 @@ class Ractor
425363 # -->
426364 # TBD
427365 #
428- def self.select : (*Ractor ractors, ?move: boolish, ?yield_value: untyped ) -> [ Ractor | Symbol, untyped ]
366+ def self.select : (? ) -> untyped
429367
430368 # <!--
431369 # rdoc-file=ractor.rb
@@ -459,46 +397,6 @@ class Ractor
459397 #
460398 def self.store_if_absent : [A] (Symbol) { (nil ) -> A } -> A
461399
462- # <!--
463- # rdoc-file=ractor.rb
464- # - Ractor.yield(msg, move: false) -> nil
465- # -->
466- # Send a message to the current ractor's outgoing port to be accepted by #take.
467- #
468- # r = Ractor.new {Ractor.yield 'Hello from ractor'}
469- # puts r.take
470- # # Prints: "Hello from ractor"
471- #
472- # This method is blocking, and will return only when somebody consumes the sent
473- # message.
474- #
475- # r = Ractor.new do
476- # Ractor.yield 'Hello from ractor'
477- # puts "Ractor: after yield"
478- # end
479- # wait
480- # puts "Still not taken"
481- # puts r.take
482- #
483- # This will print:
484- #
485- # Still not taken
486- # Hello from ractor
487- # Ractor: after yield
488- #
489- # If the outgoing port was closed with #close_outgoing, the method will raise:
490- #
491- # r = Ractor.new do
492- # close_outgoing
493- # Ractor.yield 'Hello from ractor'
494- # end
495- # wait
496- # # `yield': The outgoing-port is already closed (Ractor::ClosedError)
497- #
498- # The meaning of the `move` argument is the same as for #send.
499- #
500- def self.yield : (untyped obj, ?move: boolish) -> untyped
501-
502400 # <!--
503401 # rdoc-file=ractor.rb
504402 # - <<(...)
@@ -513,6 +411,7 @@ class Ractor
513411 # get a value from ractor-local storage for current Ractor Obsolete and use
514412 # Ractor.[] instead.
515413 #
414+ %a{deprecated: Use Ractor.[] instead}
516415 def [] : (interned sym) -> untyped
517416
518417 # <!--
@@ -522,40 +421,9 @@ class Ractor
522421 # set a value in ractor-local storage for current Ractor Obsolete and use
523422 # Ractor.[]= instead.
524423 #
424+ %a{deprecated: Use Ractor.[]= instead}
525425 def []= : [T] (interned sym, T val) -> T
526426
527- # <!--
528- # rdoc-file=ractor.rb
529- # - ractor.close_incoming -> true | false
530- # -->
531- # Closes the incoming port and returns whether it was already closed. All
532- # further attempts to Ractor.receive in the ractor, and #send to the ractor will
533- # fail with Ractor::ClosedError.
534- #
535- # r = Ractor.new {sleep(500)}
536- # r.close_incoming #=> false
537- # r.close_incoming #=> true
538- # r.send('test')
539- # # Ractor::ClosedError (The incoming-port is already closed)
540- #
541- def close_incoming : () -> bool
542-
543- # <!--
544- # rdoc-file=ractor.rb
545- # - ractor.close_outgoing -> true | false
546- # -->
547- # Closes the outgoing port and returns whether it was already closed. All
548- # further attempts to Ractor.yield in the ractor, and #take from the ractor will
549- # fail with Ractor::ClosedError.
550- #
551- # r = Ractor.new {sleep(500)}
552- # r.close_outgoing #=> false
553- # r.close_outgoing #=> true
554- # r.take
555- # # Ractor::ClosedError (The outgoing-port is already closed)
556- #
557- def close_outgoing : () -> bool
558-
559427 # <!--
560428 # rdoc-file=ractor.rb
561429 # - inspect()
@@ -579,73 +447,6 @@ class Ractor
579447 #
580448 def send : (untyped obj, ?move: boolish) -> Ractor
581449
582- # <!--
583- # rdoc-file=ractor.rb
584- # - ractor.take -> msg
585- # -->
586- # Get a message from the ractor's outgoing port, which was put there by
587- # Ractor.yield or at ractor's termination.
588- #
589- # r = Ractor.new do
590- # Ractor.yield 'explicit yield'
591- # 'last value'
592- # end
593- # puts r.take #=> 'explicit yield'
594- # puts r.take #=> 'last value'
595- # puts r.take # Ractor::ClosedError (The outgoing-port is already closed)
596- #
597- # The fact that the last value is also sent to the outgoing port means that
598- # `take` can be used as an analog of Thread#join ("just wait until ractor
599- # finishes"). However, it will raise if somebody has already consumed that
600- # message.
601- #
602- # If the outgoing port was closed with #close_outgoing, the method will raise
603- # Ractor::ClosedError.
604- #
605- # r = Ractor.new do
606- # sleep(500)
607- # Ractor.yield 'Hello from ractor'
608- # end
609- # r.close_outgoing
610- # r.take
611- # # Ractor::ClosedError (The outgoing-port is already closed)
612- # # The error would be raised immediately, not when ractor will try to receive
613- #
614- # If an uncaught exception is raised in the Ractor, it is propagated by take as
615- # a Ractor::RemoteError.
616- #
617- # r = Ractor.new {raise "Something weird happened"}
618- #
619- # begin
620- # r.take
621- # rescue => e
622- # p e # => #<Ractor::RemoteError: thrown by remote Ractor.>
623- # p e.ractor == r # => true
624- # p e.cause # => #<RuntimeError: Something weird happened>
625- # end
626- #
627- # Ractor::ClosedError is a descendant of StopIteration, so the termination of
628- # the ractor will break out of any loops that receive this message without
629- # propagating the error:
630- #
631- # r = Ractor.new do
632- # 3.times {|i| Ractor.yield "message #{i}"}
633- # "finishing"
634- # end
635- #
636- # loop {puts "Received: " + r.take}
637- # puts "Continue successfully"
638- #
639- # This will print:
640- #
641- # Received: message 0
642- # Received: message 1
643- # Received: message 2
644- # Received: finishing
645- # Continue successfully
646- #
647- def take : () -> untyped
648-
649450 # <!--
650451 # rdoc-file=ractor.rb
651452 # - to_s()
0 commit comments