summaryrefslogtreecommitdiff
path: root/ractor.c
diff options
context:
space:
mode:
authorVictor Shepelev <zverok.offline@gmail.com>2020-12-19 20:04:40 +0200
committerGitHub <noreply@github.com>2020-12-19 13:04:40 -0500
commit1f565ac6d98e902f51a0ea7b8b4aa85693deea6e (patch)
tree1b21fbe897ba138f823d2b577defb188716ae2d0 /ractor.c
parentd44671c819e104d329e604fdf9bb59bbb426afb5 (diff)
Add documentation for Ractor (#3895)
Notes
Notes: Merged-By: marcandre <github@marc-andre.ca>
Diffstat (limited to 'ractor.c')
-rw-r--r--ractor.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/ractor.c b/ractor.c
index 08150f49a3..0565827a5f 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1933,6 +1933,100 @@ ractor_moved_missing(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eRactorMovedError, "can not send any methods to a moved object");
}
+/*
+ * Document-class: Ractor::ClosedError
+ *
+ * Raised when an attempt is made to take something from the Ractor's outgoing port,
+ * but it is closed with Ractor#close_outgoing, or to send something to Ractor's
+ * incoming port, and it is closed with Ractor#close_incoming, or an attempt to
+ * send/take something with ractor which was already terminated.
+ *
+ * r = Ractor.new { sleep(500) }
+ * r.close_outgoing
+ * r.take # Ractor::ClosedError
+ *
+ * ClosedError is a descendant of StopIteration, so the closing of the ractor will break
+ * the loops without propagating the error:
+ *
+ * r = Ractor.new { 3.times { puts "Received: " + receive } }
+ *
+ * loop { r.send "test" }
+ * puts "Continue successfully"
+ *
+ * This will print:
+ *
+ * Received: test
+ * Received: test
+ * Received: test
+ * Continue successfully
+ */
+
+/*
+ * Document-class: Ractor::RemoteError
+ *
+ * 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 original ractor
+ * it was raised in.
+ *
+ * r = Ractor.new { raise "Something weird happened" }
+ *
+ * begin
+ * r.take
+ * rescue => e
+ * p e # => #<Ractor::RemoteError: thrown by remote Ractor.>
+ * p e.ractor == r # => true
+ * p e.cause # => #<RuntimeError: Something weird happened>
+ * end
+ *
+ */
+
+/*
+ * Document-class: Ractor::MovedError
+ *
+ * Raised on an attempt to access an object which was moved in Ractor#send or Ractor.yield.
+ *
+ * r = Ractor.new { sleep }
+ *
+ * ary = [1, 2, 3]
+ * r.send(ary, move: true)
+ * ary.inspect
+ * # Ractor::MovedError (can not send any methods to a moved object)
+ *
+ */
+
+/*
+ * Document-class: Ractor::MovedObject
+ *
+ * A special object which replaces any value that was moved to another ractor in Ractor#send
+ * or Ractor.yield. Any attempt to access the object results in Ractor::MovedError.
+ *
+ * r = Ractor.new { receive }
+ *
+ * ary = [1, 2, 3]
+ * r.send(ary, move: true)
+ * p Ractor::MovedObject === ary
+ * # => true
+ * ary.inspect
+ * # Ractor::MovedError (can not send any methods to a moved object)
+ *
+ * The class MovedObject is frozen to avoid tampering with it:
+ *
+ * class Ractor::MovedObject
+ * def inspect
+ * "<MyMovedObject>"
+ * end
+ * end
+ * # FrozenError (can't modify frozen class: Ractor::MovedObject)
+ */
+
+// Main docs are in ractor.rb, but without this clause there are weird artifacts
+// in their rendering.
+/*
+ * Document-class: Ractor
+ *
+ */
+
+
void
Init_Ractor(void)
{