|
49 | 49 | #
|
50 | 50 | # @see http://linux.die.net/man/3/clock_gettime Linux clock_gettime(3)
|
51 | 51 |
|
| 52 | +# @!macro [new] copy_options |
| 53 | +# |
| 54 | +# ## Copy Options |
| 55 | +# |
| 56 | +# Object references in Ruby are mutable. This can lead to serious |
| 57 | +# problems when the {#value} of an object is a mutable reference. Which |
| 58 | +# is always the case unless the value is a `Fixnum`, `Symbol`, or similar |
| 59 | +# "primative" data type. Each instance can be configured with a few |
| 60 | +# options that can help protect the program from potentially dangerous |
| 61 | +# operations. Each of these options can be optionally set when the oject |
| 62 | +# instance is created: |
| 63 | +# |
| 64 | +# * `:dup_on_deref` When true the object will call the `#dup` method on |
| 65 | +# the `value` object every time the `#value` methid is called |
| 66 | +# (default: false) |
| 67 | +# * `:freeze_on_deref` When true the object will call the `#freeze` |
| 68 | +# method on the `value` object every time the `#value` method is called |
| 69 | +# (default: false) |
| 70 | +# * `:copy_on_deref` When given a `Proc` object the `Proc` will be run |
| 71 | +# every time the `#value` method is called. The `Proc` will be given |
| 72 | +# the current `value` as its only argument and the result returned by |
| 73 | +# the block will be the return value of the `#value` call. When `nil` |
| 74 | +# this option will be ignored (default: nil) |
| 75 | +# |
| 76 | +# When multiple deref options are set the order of operations is strictly defined. |
| 77 | +# The order of deref operations is: |
| 78 | +# * `:copy_on_deref` |
| 79 | +# * `:dup_on_deref` |
| 80 | +# * `:freeze_on_deref` |
| 81 | +# |
| 82 | +# Because of this ordering there is no need to `#freeze` an object created by a |
| 83 | +# provided `:copy_on_deref` block. Simply set `:freeze_on_deref` to `true`. |
| 84 | +# Setting both `:dup_on_deref` to `true` and `:freeze_on_deref` to `true` is |
| 85 | +# as close to the behavior of a "pure" functional language (like Erlang, Clojure, |
| 86 | +# or Haskell) as we are likely to get in Ruby. |
| 87 | + |
| 88 | +# @!macro [attach] deref_options |
| 89 | +# |
| 90 | +# @option opts [Boolean] :dup_on_deref (false) Call `#dup` before |
| 91 | +# returning the data from {#value} |
| 92 | +# @option opts [Boolean] :freeze_on_deref (false) Call `#freeze` before |
| 93 | +# returning the data from {#value} |
| 94 | +# @option opts [Proc] :copy_on_deref (nil) When calling the {#value} |
| 95 | +# method, call the given proc passing the internal value as the sole |
| 96 | +# argument then return the new value returned from the proc. |
| 97 | + |
| 98 | +# @!macro [attach] executor_and_deref_options |
| 99 | +# |
| 100 | +# @param [Hash] opts the options used to define the behavior at update and deref |
| 101 | +# and to specify the executor on which to perform actions |
| 102 | +# @option opts [Executor] :executor when set use the given `Executor` instance. |
| 103 | +# Three special values are also supported: `:task` returns the global task pool, |
| 104 | +# `:operation` returns the global operation pool, and `:immediate` returns a new |
| 105 | +# `ImmediateExecutor` object. |
| 106 | +# @!macro deref_options |
| 107 | + |
52 | 108 | # Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell,
|
53 | 109 | # F#, C#, Java, and classic concurrency patterns.
|
54 | 110 | #
|
|
0 commit comments