diff --git a/core/fiber.rbs b/core/fiber.rbs index 20b4f8773..d24f1796d 100644 --- a/core/fiber.rbs +++ b/core/fiber.rbs @@ -425,8 +425,8 @@ class Fiber < Object # # See Kernel#raise for more information. # - def raise: (?string msg) -> untyped - | (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace) -> untyped + def raise: (?string msg, ?cause: Exception?) -> untyped + | (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> untyped # + # Returns "exp(x) - 1", `e` raised to the `x` power, minus 1. + # + # * Domain: `[-INFINITY, INFINITY]`. + # * Range: `[-1.0, INFINITY]`. + # + # Examples: + # + # expm1(-INFINITY) # => 0.0 + # expm1(-1.0) # => -0.6321205588285577 # 1.0/E - 1 + # expm1(0.0) # => 0.0 + # expm1(0.5) # => 0.6487212707001282 # sqrt(E) - 1 + # expm1(1.0) # => 1.718281828459045 # E - 1 + # expm1(2.0) # => 6.38905609893065 # E**2 - 1 + # expm1(INFINITY) # => Infinity + # + def self.expm1: (double x) -> Float + # + # Returns "log(x + 1)", the base E + # [logarithm](https://en.wikipedia.org/wiki/Logarithm) of (`x` + 1). + # + # * Domain: `[-1, INFINITY]`. + # * Range: `[-INFINITY, INFINITY]`. + # + # Examples: + # + # log1p(-1.0) # => -Infinity + # log1p(0.0) # => 0.0 + # log1p(E - 1) # => 1.0 + # log1p(INFINITY) # => Infinity + # + def self.log1p: (double x) -> Float + # # + %a{deprecated} def self._id2ref: (Integer id) -> untyped # # TBD # - def self.select: (?) -> untyped + def self.select: (?) -> Array[untyped] # + # It returns shareable Proc object. The Proc object is shareable and the self in + # a block will be replaced with the value passed via `self:` keyword. + # + # In a shareable Proc, you can not access to the outer variables. + # + # a = 42 + # Ractor.shareable_proc{ p a } + # #=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError) + # + # The `self` should be a sharable object + # + # Ractor.shareable_proc(self: self){} + # #=> self should be shareable: main (Ractor::IsolationError) + # + def self.shareable_proc: [T] () { (?) [self: nil] -> T } -> ^(?) [self: nil] -> T + | [T, S] (self: S) { (?) [self: S] -> T } -> ^(?) [self: S] -> T + + # + # Same as Ractor.sharable_proc, but returns lambda proc. + # + def self.shareable_lambda: [T] () { (?) [self: nil] -> T } -> ^(?) [self: nil] -> T + | [T, S] (self: S) { (?) [self: S] -> T } -> ^(?) [self: S] -> T + # + # return default port of the Ractor. + # + def default_port: () -> Port[untyped] + # + # Wait for the termination of the Ractor. If the Ractor was aborted (terminated + # with an exception), Ractor#value is called to raise an exception. + # + # Ractor.new{}.join #=> ractor + # + # Ractor.new{ raise "foo" }.join + # #=> raise an exception "foo (RuntimeError)" + # + def join: () -> self + # + # Register port as a monitoring port. If the ractor terminated, the port + # received a Symbol object. :exited will be sent if the ractor terminated + # without an exception. :aborted will be sent if the ractor terminated with a + # exception. + # + # r = Ractor.new{ some_task() } + # r.monitor(port = Ractor::Port.new) + # port.receive #=> :exited and r is terminated + # + # r = Ractor.new{ raise "foo" } + # r.monitor(port = Ractor::Port.new) + # port.receive #=> :terminated and r is terminated with an exception "foo" + # + def monitor: [T < Symbol] (Port[T]) -> untyped + # + # Unregister port from the monitoring ports. + # + def unmonitor: (Port[untyped]) -> self + + # + # Waits for `ractor` to complete, using #join, and return its value or raise the + # exception which terminated the Ractor. The value will not be copied even if it + # is unshareable object. Therefore at most 1 Ractor can get a value. + # + # r = Ractor.new{ [1, 2] } + # r.value #=> [1, 2] (unshareable object) + # + # Ractor.new(r){|r| r.value} #=> Ractor::Error + # + def value: () -> untyped + private # + # Port objects transmit messages between Ractors. + # + class Port[T = untyped] + # + # + alias << send + + # + # Close the port. On the closed port, sending is not prohibited. Receiving is + # also not allowed if there is no sent messages arrived before closing. + # + # port = Ractor::Port.new + # Ractor.new port do |port| + # port.send 1 # OK + # port.send 2 # OK + # port.close + # port.send 3 # raise Ractor::ClosedError + # end + # + # port.receive #=> 1 + # port.receive #=> 2 + # port.receive #=> raise Ractor::ClosedError + # + # Now, only a Ractor which creates the port is allowed to close ports. + # + # port = Ractor::Port.new + # Ractor.new port do |port| + # port.close #=> closing port by other ractors is not allowed (Ractor::Error) + # end.join + # + def close: () -> void + + # + # Return the port is closed or not. + # + def closed?: () -> bool + + # + # + def inspect: () -> String + + # + # Receive a message to the port (which was sent there by Port#send). + # + # port = Ractor::Port.new + # r = Ractor.new port do |port| + # port.send('message1') + # end + # + # v1 = port.receive + # puts "Received: #{v1}" + # r.join + # # Here will be printed: "Received: message1" + # + # The method blocks if the message queue is empty. + # + # port = Ractor::Port.new + # r = Ractor.new port do |port| + # wait + # puts "Still not received" + # port.send('message1') + # wait + # puts "Still received only one" + # port.send('message2') + # end + # puts "Before first receive" + # v1 = port.receive + # puts "Received: #{v1}" + # v2 = port.receive + # puts "Received: #{v2}" + # r.join + # + # Output: + # + # Before first receive + # Still not received + # Received: message1 + # Still received only one + # Received: message2 + # + # If close_incoming was called on the ractor, the method raises + # Ractor::ClosedError if there are no more messages in the message queue: + # + # port = Ractor::Port.new + # port.close + # port.receive #=> raise Ractor::ClosedError + # + def receive: () -> T + + # + # Send a message to a port to be accepted by port.receive. + # + # port = Ractor::Port.new + # r = Ractor.new do + # r.send 'message' + # end + # value = port.receive + # puts "Received #{value}" + # # Prints: "Received: message" + # + # The method is non-blocking (will return immediately even if the ractor is not + # ready to receive anything): + # + # port = Ractor::Port.new + # r = Ractor.new(port) do |port| + # port.send 'test'} + # puts "Sent successfully" + # # Prints: "Sent successfully" immediately + # end + # + # An attempt to send to a port which already closed its execution will raise + # Ractor::ClosedError. + # + # r = Ractor.new {Ractor::Port.new} + # r.join + # p r + # # "#" + # port = r.value + # port.send('test') # raise Ractor::ClosedError + # + # If the `obj` is unshareable, by default it will be copied into the receiving + # ractor by deep cloning. + # + # If the object is shareable, it only send a reference to the object without + # cloning. + # + def send: (T obj, ?move: boolish) -> self + + private + + # + # Returns a new Ractor::Port object. + # + def initialize: () -> void + + def initialize_copy: (untyped) -> untyped + end + # # Raised on attempt to Ractor#take if there was an uncaught exception in the # Ractor. Its `cause` will contain the original exception, and `ractor` is the diff --git a/core/thread.rbs b/core/thread.rbs index 974fbd70b..bb63ae41d 100644 --- a/core/thread.rbs +++ b/core/thread.rbs @@ -974,8 +974,8 @@ class Thread < Object # from prog.rb:2:in `new' # from prog.rb:2 # - def raise: (?String message) -> nil - | (_Exception, ?_ToS message, ?Array[Thread::Backtrace::Location] | Array[String] | nil backtrace) -> nil + def raise: (?String message, ?cause: Exception?) -> nil + | (_Exception, ?_ToS message, ?Array[Thread::Backtrace::Location] | Array[String] | nil backtrace, ?cause: Exception?) -> nil #