code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def eql?(other)
self.class.eql?(other.class) &&
@type.eql?(other.type) &&
@children.eql?(other.children)
end | Test if other object is equal to
@param [Object] other
@return [Boolean] | eql? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def assign_properties(properties)
properties.each do |name, value|
instance_variable_set :"@#{name}", value
end
nil
end | By default, each entry in the `properties` hash is assigned to
an instance variable in this instance of Node. A subclass should define
attribute readers for such variables. The values passed in the hash
are not frozen or whitelisted; such behavior can also be implemented
by subclassing Node and overriding this method.
@return [nil] | assign_properties | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def updated(type=nil, children=nil, properties=nil)
new_type = type || @type
new_children = children || @children
new_properties = properties || {}
if @type == new_type &&
@children == new_children &&
properties.nil?
self
else
copy = original_dup
copy.send :initialize, new_type, new_children, new_properties
copy
end
end | Returns a new instance of Node where non-nil arguments replace the
corresponding fields of `self`.
For example, `Node.new(:foo, [ 1, 2 ]).updated(:bar)` would yield
`(bar 1 2)`, and `Node.new(:foo, [ 1, 2 ]).updated(nil, [])` would
yield `(foo)`.
If the resulting node would be identical to `self`, does nothing.
@param [Symbol, nil] type
@param [Array, nil] children
@param [Hash, nil] properties
@return [AST::Node] | updated | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def concat(array)
updated(nil, @children + array.to_a)
end | Concatenates `array` with `children` and returns the resulting node.
@return [AST::Node] | concat | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def append(element)
updated(nil, @children + [element])
end | Appends `element` to `children` and returns the resulting node.
@return [AST::Node] | append | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def to_sexp(indent=0)
indented = " " * indent
sexp = "#{indented}(#{fancy_type}"
children.each do |child|
if child.is_a?(Node)
sexp += "\n#{child.to_sexp(indent + 1)}"
else
sexp += " #{child.inspect}"
end
end
sexp += ")"
sexp
end | Converts `self` to a pretty-printed s-expression.
@param [Integer] indent Base indentation level.
@return [String] | to_sexp | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def inspect(indent=0)
indented = " " * indent
sexp = "#{indented}s(:#{@type}"
children.each do |child|
if child.is_a?(Node)
sexp += ",\n#{child.inspect(indent + 1)}"
else
sexp += ", #{child.inspect}"
end
end
sexp += ")"
sexp
end | Converts `self` to a s-expression ruby string.
The code return will recreate the node, using the sexp module s()
@param [Integer] indent Base indentation level.
@return [String] | inspect | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def to_sexp_array
children_sexp_arrs = children.map do |child|
if child.is_a?(Node)
child.to_sexp_array
else
child
end
end
[type, *children_sexp_arrs]
end | Converts `self` to an Array where the first element is the type as a Symbol,
and subsequent elements are the same representation of its children.
@return [Array<Symbol, [...Array]>] | to_sexp_array | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def deconstruct
[type, *children]
end | Enables matching for Node, where type is the first element
and the children are remaining items.
@return [Array] | deconstruct | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def fancy_type
@type.to_s.gsub('_', '-')
end | Returns `@type` with all underscores replaced by dashes. This allows
to write symbol literals without quotes in Ruby sources and yet have
nicely looking s-expressions.
@return [String] | fancy_type | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/node.rb | Apache-2.0 |
def s(type, *children)
Node.new(type, children)
end | Creates a {Node} with type `type` and children `children`.
Note that the resulting node is of the type AST::Node and not a
subclass.
This would not pose a problem with comparisons, as {Node#==}
ignores metadata. | s | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/sexp.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/sexp.rb | Apache-2.0 |
def process(node)
return if node.nil?
node = node.to_ast
# Invoke a specific handler
on_handler = :"on_#{node.type}"
if respond_to? on_handler
new_node = send on_handler, node
else
new_node = handler_missing(node)
end
node = new_node if new_node
node
end | Dispatches `node`. If a node has type `:foo`, then a handler
named `on_foo` is invoked with one argument, the `node`; if
there isn't such a handler, {#handler_missing} is invoked
with the same argument.
If the handler returns `nil`, `node` is returned; otherwise,
the return value of the handler is passed along.
@param [AST::Node, nil] node
@return [AST::Node, nil] | process | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/processor/mixin.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/processor/mixin.rb | Apache-2.0 |
def process_all(nodes)
nodes.to_a.map do |node|
process node
end
end | {#process}es each node from `nodes` and returns an array of
results.
@param [Array<AST::Node>] nodes
@return [Array<AST::Node>] | process_all | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/processor/mixin.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ast-2.4.2/lib/ast/processor/mixin.rb | Apache-2.0 |
def compile(script, options = {})
script = script.read if script.respond_to?(:read)
if options.key?(:bare)
elsif options.key?(:no_wrap)
options[:bare] = options[:no_wrap]
else
options[:bare] = false
end
# Stringify keys
options = options.inject({}) { |h, (k, v)| h[k.to_s] = v; h }
Source.context.call("compile", script, options)
end | Compile a script (String or IO) to JavaScript. | compile | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/coffee-script-2.4.1/lib/coffee_script.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/coffee-script-2.4.1/lib/coffee_script.rb | Apache-2.0 |
def has_ansi?(str)
str.match(ANSI_MATCHR).is_a?(
MatchData
)
end | --------------------------------------------------------------------------
Allows you to check if a string currently has ansi.
-------------------------------------------------------------------------- | has_ansi? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | Apache-2.0 |
def ansi_jump(str, num)
"\x1b[#{num}A#{clear_line(str)}\x1b[#{
num
}B"
end | --------------------------------------------------------------------------
Jump the cursor, moving it up and then back down to it's spot, allowing
you to do fancy things like multiple output (downloads) the way that Docker
does them in an async way without breaking term.
-------------------------------------------------------------------------- | ansi_jump | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | Apache-2.0 |
def strip_ansi(str)
str.gsub(
ANSI_MATCHR, ""
)
end | --------------------------------------------------------------------------
Strip ANSI from the current string, making it just a normal string.
-------------------------------------------------------------------------- | strip_ansi | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | Apache-2.0 |
def clear_screen(str = "")
"\x1b[H\x1b[2J#{
str
}"
end | --------------------------------------------------------------------------
Clear the screen's current view, so the user gets a clean output.
-------------------------------------------------------------------------- | clear_screen | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/colorator-1.1.0/lib/colorator.rb | Apache-2.0 |
def render_html(text, options = :DEFAULT, extensions = [])
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
opts = Config.process_options(options, :render)
Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
end | Public: Parses a Markdown string into an HTML string.
text - A {String} of text
option - Either a {Symbol} or {Array of Symbol}s indicating the render options
extensions - An {Array of Symbol}s indicating the extensions to use
Returns a {String} of converted HTML. | render_html | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker.rb | Apache-2.0 |
def render_doc(text, options = :DEFAULT, extensions = [])
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
opts = Config.process_options(options, :parse)
text = text.encode("UTF-8")
Node.parse_document(text, text.bytesize, opts, extensions)
end | Public: Parses a Markdown string into a `document` node.
string - {String} to be parsed
option - A {Symbol} or {Array of Symbol}s indicating the parse options
extensions - An {Array of Symbol}s indicating the extensions to use
Returns the `document` node. | render_doc | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker.rb | Apache-2.0 |
def walk(&block)
return enum_for(:walk) unless block
yield self
each do |child|
child.walk(&block)
end
end | Public: An iterator that "walks the tree," descending into children recursively.
blk - A {Proc} representing the action to take for each child | walk | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def to_html(options = :DEFAULT, extensions = [])
opts = Config.process_options(options, :render)
_render_html(opts, extensions).force_encoding("utf-8")
end | Public: Convert the node to an HTML string.
options - A {Symbol} or {Array of Symbol}s indicating the render options
extensions - An {Array of Symbol}s indicating the extensions to use
Returns a {String}. | to_html | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def to_xml(options = :DEFAULT)
opts = Config.process_options(options, :render)
_render_xml(opts).force_encoding("utf-8")
end | Public: Convert the node to an XML string.
options - A {Symbol} or {Array of Symbol}s indicating the render options
Returns a {String}. | to_xml | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def to_commonmark(options = :DEFAULT, width = 120)
opts = Config.process_options(options, :render)
_render_commonmark(opts, width).force_encoding("utf-8")
end | Public: Convert the node to a CommonMark string.
options - A {Symbol} or {Array of Symbol}s indicating the render options
width - Column to wrap the output at
Returns a {String}. | to_commonmark | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def to_plaintext(options = :DEFAULT, width = 120)
opts = Config.process_options(options, :render)
_render_plaintext(opts, width).force_encoding("utf-8")
end | Public: Convert the node to a plain text string.
options - A {Symbol} or {Array of Symbol}s indicating the render options
width - Column to wrap the output at
Returns a {String}. | to_plaintext | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def each
return enum_for(:each) unless block_given?
child = first_child
while child
nextchild = child.next
yield child
child = nextchild
end
end | Public: Iterate over the children (if any) of the current pointer. | each | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/commonmarker-0.23.9/lib/commonmarker/node.rb | Apache-2.0 |
def initialize(initial, opts = {})
super()
synchronize { ns_initialize(initial, opts) }
end | Create a new `Agent` with the given initial value and options.
The `:validator` option must be `nil` or a side-effect free proc/lambda
which takes one argument. On any intended value change the validator, if
provided, will be called. If the new value is invalid the validator should
return `false` or raise an error.
The `:error_handler` option must be `nil` or a proc/lambda which takes two
arguments. When an action raises an error or validation fails, either by
returning false or raising an error, the error handler will be called. The
arguments to the error handler will be a reference to the agent itself and
the error object which was raised.
The `:error_mode` may be either `:continue` (the default if an error
handler is given) or `:fail` (the default if error handler nil or not
given).
If an action being run by the agent throws an error or doesn't pass
validation the error handler, if present, will be called. After the
handler executes if the error mode is `:continue` the Agent will continue
as if neither the action that caused the error nor the error itself ever
happened.
If the mode is `:fail` the Agent will become {#failed?} and will stop
accepting new action dispatches. Any previously queued actions will be
held until {#restart} is called. The {#value} method will still work,
returning the value of the Agent before the error.
@param [Object] initial the initial value
@param [Hash] opts the configuration options
@option opts [Symbol] :error_mode either `:continue` or `:fail`
@option opts [nil, Proc] :error_handler the (optional) error handler
@option opts [nil, Proc] :validator the (optional) validation procedure | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def value
@current.value # TODO (pitr 12-Sep-2015): broken unsafe read?
end | The current value (state) of the Agent, irrespective of any pending or
in-progress actions. The value is always available and is non-blocking.
@return [Object] the current value | value | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def send!(*args, &action)
raise Error.new unless send(*args, &action)
true
end | @!macro agent_send
@!macro send_bang_return_and_raise
@return [Boolean] true if the action is successfully enqueued
@raise [Concurrent::Agent::Error] if the Agent is {#failed?} | send! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def send_via(executor, *args, &action)
enqueue_action_job(action, args, executor)
end | @!macro agent_send
@!macro send_return
@param [Concurrent::ExecutorService] executor the executor on which the
action is to be dispatched | send_via | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def send_via!(executor, *args, &action)
raise Error.new unless send_via(executor, *args, &action)
true
end | @!macro agent_send
@!macro send_bang_return_and_raise
@param [Concurrent::ExecutorService] executor the executor on which the
action is to be dispatched | send_via! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def await
wait(nil)
self
end | Blocks the current thread (indefinitely!) until all actions dispatched
thus far, from this thread or nested by the Agent, have occurred. Will
block when {#failed?}. Will never return if a failed Agent is {#restart}
with `:clear_actions` true.
Returns a reference to `self` to support method chaining:
```
current_value = agent.await.value
```
@return [Boolean] self
@!macro agent_await_warning | await | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def await_for!(timeout)
raise Concurrent::TimeoutError unless wait(timeout.to_f)
true
end | Blocks the current thread until all actions dispatched thus far, from this
thread or nested by the Agent, have occurred, or the timeout (in seconds)
has elapsed.
@param [Float] timeout the maximum number of seconds to wait
@return [Boolean] true if all actions complete before timeout
@raise [Concurrent::TimeoutError] when timout is reached
@!macro agent_await_warning | await_for! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def wait(timeout = nil)
latch = Concurrent::CountDownLatch.new(1)
enqueue_await_job(latch)
latch.wait(timeout)
end | Blocks the current thread until all actions dispatched thus far, from this
thread or nested by the Agent, have occurred, or the timeout (in seconds)
has elapsed. Will block indefinitely when timeout is nil or not given.
Provided mainly for consistency with other classes in this library. Prefer
the various `await` methods instead.
@param [Float] timeout the maximum number of seconds to wait
@return [Boolean] true if all actions complete before timeout else false
@!macro agent_await_warning | wait | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def restart(new_value, opts = {})
clear_actions = opts.fetch(:clear_actions, false)
synchronize do
raise Error.new('agent is not failed') unless failed?
raise ValidationError unless ns_validate(new_value)
@current.value = new_value
@error.value = nil
@queue.clear if clear_actions
ns_post_next_job unless @queue.empty?
end
true
end | When an Agent is {#failed?}, changes the Agent {#value} to `new_value`
then un-fails the Agent so that action dispatches are allowed again. If
the `:clear_actions` option is give and true, any actions queued on the
Agent that were being held while it was failed will be discarded,
otherwise those held actions will proceed. The `new_value` must pass the
validator if any, or `restart` will raise an exception and the Agent will
remain failed with its old {#value} and {#error}. Observers, if any, will
not be notified of the new state.
@param [Object] new_value the new value for the Agent once restarted
@param [Hash] opts the configuration options
@option opts [Symbol] :clear_actions true if all enqueued but unprocessed
actions should be discarded on restart, else false (default: false)
@return [Boolean] true
@raise [Concurrent:AgentError] when not failed | restart | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def await(*agents)
agents.each { |agent| agent.await }
true
end | Blocks the current thread (indefinitely!) until all actions dispatched
thus far to all the given Agents, from this thread or nested by the
given Agents, have occurred. Will block when any of the agents are
failed. Will never return if a failed Agent is restart with
`:clear_actions` true.
@param [Array<Concurrent::Agent>] agents the Agents on which to wait
@return [Boolean] true
@!macro agent_await_warning | await | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def await_for(timeout, *agents)
end_at = Concurrent.monotonic_time + timeout.to_f
ok = agents.length.times do |i|
break false if (delay = end_at - Concurrent.monotonic_time) < 0
break false unless agents[i].await_for(delay)
end
!!ok
end | Blocks the current thread until all actions dispatched thus far to all
the given Agents, from this thread or nested by the given Agents, have
occurred, or the timeout (in seconds) has elapsed.
@param [Float] timeout the maximum number of seconds to wait
@param [Array<Concurrent::Agent>] agents the Agents on which to wait
@return [Boolean] true if all actions complete before timeout else false
@!macro agent_await_warning | await_for | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def await_for!(timeout, *agents)
raise Concurrent::TimeoutError unless await_for(timeout, *agents)
true
end | Blocks the current thread until all actions dispatched thus far to all
the given Agents, from this thread or nested by the given Agents, have
occurred, or the timeout (in seconds) has elapsed.
@param [Float] timeout the maximum number of seconds to wait
@param [Array<Concurrent::Agent>] agents the Agents on which to wait
@return [Boolean] true if all actions complete before timeout
@raise [Concurrent::TimeoutError] when timout is reached
@!macro agent_await_warning | await_for! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/agent.rb | Apache-2.0 |
def initialize(delegate)
super()
@delegate = delegate
@queue = []
@executor = Concurrent.global_io_executor
@ruby_pid = $$
end | Create a new delegator object wrapping the given delegate.
@param [Object] delegate the object to wrap and delegate method calls to | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def method_missing(method, *args, &block)
super unless @delegate.respond_to?(method)
Async::validate_argc(@delegate, method, *args)
ivar = Concurrent::IVar.new
synchronize do
reset_if_forked
@queue.push [ivar, method, args, block]
@executor.post { perform } if @queue.length == 1
end
ivar
end | Delegates method calls to the wrapped object.
@param [Symbol] method the method being called
@param [Array] args zero or more arguments to the method
@return [IVar] the result of the method call
@raise [NameError] the object does not respond to `method` method
@raise [ArgumentError] the given `args` do not match the arity of `method` | method_missing | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def respond_to_missing?(method, include_private = false)
@delegate.respond_to?(method) || super
end | Check whether the method is responsive
@param [Symbol] method the method being called | respond_to_missing? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def perform
loop do
ivar, method, args, block = synchronize { @queue.first }
break unless ivar # queue is empty
begin
ivar.set(@delegate.send(method, *args, &block))
rescue => error
ivar.fail(error)
end
synchronize do
@queue.shift
return if @queue.empty?
end
end
end | Perform all enqueued tasks.
This method must be called from within the executor. It must not be
called while already running. It will loop until the queue is empty. | perform | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def initialize(delegate)
@delegate = delegate
end | Create a new delegator object wrapping the given delegate.
@param [AsyncDelegator] delegate the object to wrap and delegate method calls to | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def method_missing(method, *args, &block)
ivar = @delegate.send(method, *args, &block)
ivar.wait
ivar
end | Delegates method calls to the wrapped object.
@param [Symbol] method the method being called
@param [Array] args zero or more arguments to the method
@return [IVar] the result of the method call
@raise [NameError] the object does not respond to `method` method
@raise [ArgumentError] the given `args` do not match the arity of `method` | method_missing | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def respond_to_missing?(method, include_private = false)
@delegate.respond_to?(method) || super
end | Check whether the method is responsive
@param [Symbol] method the method being called | respond_to_missing? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def init_synchronization
return self if defined?(@__async_initialized__) && @__async_initialized__
@__async_initialized__ = true
@__async_delegator__ = AsyncDelegator.new(self)
@__await_delegator__ = AwaitDelegator.new(@__async_delegator__)
self
end | Initialize the internal serializer and other stnchronization mechanisms.
@note This method *must* be called immediately upon object construction.
This is the only way thread-safe initialization can be guaranteed.
@!visibility private | init_synchronization | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/async.rb | Apache-2.0 |
def initialize(value, opts = {})
super()
@Validator = opts.fetch(:validator, -> v { true })
self.observers = Collection::CopyOnNotifyObserverSet.new
self.value = value
end | @!method value
The current value of the atom.
@return [Object] The current value.
Create a new atom with the given initial value.
@param [Object] value The initial value
@param [Hash] opts The options used to configure the atom
@option opts [Proc] :validator (nil) Optional proc used to validate new
values. It must accept one and only one argument which will be the
intended new value. The validator will return true if the new value
is acceptable else return false (preferrably) or raise an exception.
@!macro deref_options
@raise [ArgumentError] if the validator is not a `Proc` (when given) | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | Apache-2.0 |
def swap(*args)
raise ArgumentError.new('no block given') unless block_given?
loop do
old_value = value
new_value = yield(old_value, *args)
begin
break old_value unless valid?(new_value)
break new_value if compare_and_set(old_value, new_value)
rescue
break old_value
end
end
end | Atomically swaps the value of atom using the given block. The current
value will be passed to the block, as will any arguments passed as
arguments to the function. The new value will be validated against the
(optional) validator proc given at construction. If validation fails the
value will not be changed.
Internally, {#swap} reads the current value, applies the block to it, and
attempts to compare-and-set it in. Since another thread may have changed
the value in the intervening time, it may have to retry, and does so in a
spin loop. The net effect is that the value will always be the result of
the application of the supplied block to a current value, atomically.
However, because the block might be called multiple times, it must be free
of side effects.
@note The given block may be called multiple times, and thus should be free
of side effects.
@param [Object] args Zero or more arguments passed to the block.
@yield [value, args] Calculates a new value for the atom based on the
current value and any supplied arguments.
@yieldparam value [Object] The current value of the atom.
@yieldparam args [Object] All arguments passed to the function, in order.
@yieldreturn [Object] The intended new value of the atom.
@return [Object] The final value of the atom after all operations and
validations are complete.
@raise [ArgumentError] When no block is given. | swap | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | Apache-2.0 |
def compare_and_set(old_value, new_value)
if valid?(new_value) && compare_and_set_value(old_value, new_value)
observers.notify_observers(Time.now, old_value, new_value)
true
else
false
end
end | Atomically sets the value of atom to the new value if and only if the
current value of the atom is identical to the old value and the new
value successfully validates against the (optional) validator given
at construction.
@param [Object] old_value The expected current value.
@param [Object] new_value The intended new value.
@return [Boolean] True if the value is changed else false. | compare_and_set | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | Apache-2.0 |
def reset(new_value)
old_value = value
if valid?(new_value)
self.value = new_value
observers.notify_observers(Time.now, old_value, new_value)
new_value
else
old_value
end
end | Atomically sets the value of atom to the new value without regard for the
current value so long as the new value successfully validates against the
(optional) validator given at construction.
@param [Object] new_value The intended new value.
@return [Object] The final value of the atom after all operations and
validations are complete. | reset | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | Apache-2.0 |
def valid?(new_value)
@Validator.call(new_value)
rescue
false
end | Is the new value valid?
@param [Object] new_value The intended new value.
@return [Boolean] false if the validator function returns false or raises
an exception else true | valid? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/atom.rb | Apache-2.0 |
def dataflow(*inputs, &block)
dataflow_with(Concurrent.global_io_executor, *inputs, &block)
end | Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
{include:file:docs-source/dataflow.md}
@param [Future] inputs zero or more `Future` operations that this dataflow depends upon
@yield The operation to perform once all the dependencies are met
@yieldparam [Future] inputs each of the `Future` inputs to the dataflow
@yieldreturn [Object] the result of the block operation
@return [Object] the result of all the operations
@raise [ArgumentError] if no block is given
@raise [ArgumentError] if any of the inputs are not `IVar`s | dataflow | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/dataflow.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/dataflow.rb | Apache-2.0 |
def initialize(opts = {}, &block)
raise ArgumentError.new('no block given') unless block_given?
super(&nil)
synchronize { ns_initialize(opts, &block) }
end | NOTE: Because the global thread pools are lazy-loaded with these objects
there is a performance hit every time we post a new task to one of these
thread pools. Subsequently it is critical that `Delay` perform as fast
as possible post-completion. This class has been highly optimized using
the benchmark script `examples/lazy_and_delay.rb`. Do NOT attempt to
DRY-up this class or perform other refactoring with running the
benchmarks and ensuring that performance is not negatively impacted.
Create a new `Delay` in the `:pending` state.
@!macro executor_and_deref_options
@yield the delayed operation to perform
@raise [ArgumentError] if no block is given | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | Apache-2.0 |
def value(timeout = nil)
if @executor # TODO (pitr 12-Sep-2015): broken unsafe read?
super
else
# this function has been optimized for performance and
# should not be modified without running new benchmarks
synchronize do
execute = @evaluation_started = true unless @evaluation_started
if execute
begin
set_state(true, @task.call, nil)
rescue => ex
set_state(false, nil, ex)
end
elsif incomplete?
raise IllegalOperationError, 'Recursive call to #value during evaluation of the Delay'
end
end
if @do_nothing_on_deref
@value
else
apply_deref_options(@value)
end
end
end | Return the value this object represents after applying the options
specified by the `#set_deref_options` method. If the delayed operation
raised an exception this method will return nil. The exception object
can be accessed via the `#reason` method.
@param [Numeric] timeout the maximum number of seconds to wait
@return [Object] the current value of the object
@!macro delay_note_regarding_blocking | value | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | Apache-2.0 |
def value!(timeout = nil)
if @executor
super
else
result = value
raise @reason if @reason
result
end
end | Return the value this object represents after applying the options
specified by the `#set_deref_options` method. If the delayed operation
raised an exception, this method will raise that exception (even when)
the operation has already been executed).
@param [Numeric] timeout the maximum number of seconds to wait
@return [Object] the current value of the object
@raise [Exception] when `#rejected?` raises `#reason`
@!macro delay_note_regarding_blocking | value! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | Apache-2.0 |
def wait(timeout = nil)
if @executor
execute_task_once
super(timeout)
else
value
end
self
end | Return the value this object represents after applying the options
specified by the `#set_deref_options` method.
@param [Integer] timeout (nil) the maximum number of seconds to wait for
the value to be computed. When `nil` the caller will block indefinitely.
@return [Object] self
@!macro delay_note_regarding_blocking | wait | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | Apache-2.0 |
def reconfigure(&block)
synchronize do
raise ArgumentError.new('no block given') unless block_given?
unless @evaluation_started
@task = block
true
else
false
end
end
end | Reconfigures the block returning the value if still `#incomplete?`
@yield the delayed operation to perform
@return [true, false] if success | reconfigure | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/delay.rb | Apache-2.0 |
def exchange(value, timeout = nil)
(value = do_exchange(value, timeout)) == CANCEL ? nil : value
end | @!macro exchanger_method_do_exchange
Waits for another thread to arrive at this exchange point (unless the
current thread is interrupted), and then transfers the given object to
it, receiving its object in return. The timeout value indicates the
approximate number of seconds the method should block while waiting
for the exchange. When the timeout value is `nil` the method will
block indefinitely.
@param [Object] value the value to exchange with another thread
@param [Numeric, nil] timeout in seconds, `nil` blocks indefinitely
@!macro exchanger_method_exchange
In some edge cases when a `timeout` is given a return value of `nil` may be
ambiguous. Specifically, if `nil` is a valid value in the exchange it will
be impossible to tell whether `nil` is the actual return value or if it
signifies timeout. When `nil` is a valid value in the exchange consider
using {#exchange!} or {#try_exchange} instead.
@return [Object] the value exchanged by the other thread or `nil` on timeout | exchange | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def exchange!(value, timeout = nil)
if (value = do_exchange(value, timeout)) == CANCEL
raise Concurrent::TimeoutError
else
value
end
end | @!macro exchanger_method_do_exchange
@!macro exchanger_method_exchange_bang
On timeout a {Concurrent::TimeoutError} exception will be raised.
@return [Object] the value exchanged by the other thread
@raise [Concurrent::TimeoutError] on timeout | exchange! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def try_exchange(value, timeout = nil)
if (value = do_exchange(value, timeout)) == CANCEL
Concurrent::Maybe.nothing(Concurrent::TimeoutError)
else
Concurrent::Maybe.just(value)
end
end | @!macro exchanger_method_do_exchange
@!macro exchanger_method_try_exchange
The return value will be a {Concurrent::Maybe} set to `Just` on success or
`Nothing` on timeout.
@return [Concurrent::Maybe] on success a `Just` maybe will be returned with
the item exchanged by the other thread as `#value`; on timeout a
`Nothing` maybe will be returned with {Concurrent::TimeoutError} as `#reason`
@example
exchanger = Concurrent::Exchanger.new
result = exchanger.exchange(:foo, 0.5)
if result.just?
puts result.value #=> :bar
else
puts 'timeout'
end | try_exchange | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def do_exchange(value, timeout)
raise NotImplementedError
end | @!macro exchanger_method_do_exchange
@return [Object, CANCEL] the value exchanged by the other thread; {CANCEL} on timeout | do_exchange | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def do_exchange(value, timeout)
# ALGORITHM
#
# From the original Java version:
#
# > The basic idea is to maintain a "slot", which is a reference to
# > a Node containing both an Item to offer and a "hole" waiting to
# > get filled in. If an incoming "occupying" thread sees that the
# > slot is null, it CAS'es (compareAndSets) a Node there and waits
# > for another to invoke exchange. That second "fulfilling" thread
# > sees that the slot is non-null, and so CASes it back to null,
# > also exchanging items by CASing the hole, plus waking up the
# > occupying thread if it is blocked. In each case CAS'es may
# > fail because a slot at first appears non-null but is null upon
# > CAS, or vice-versa. So threads may need to retry these
# > actions.
#
# This version:
#
# An exchange occurs between an "occupier" thread and a "fulfiller" thread.
# The "slot" is used to setup this interaction. The first thread in the
# exchange puts itself into the slot (occupies) and waits for a fulfiller.
# The second thread removes the occupier from the slot and attempts to
# perform the exchange. Removing the occupier also frees the slot for
# another occupier/fulfiller pair.
#
# Because the occupier and the fulfiller are operating independently and
# because there may be contention with other threads, any failed operation
# indicates contention. Both the occupier and the fulfiller operate within
# spin loops. Any failed actions along the happy path will cause the thread
# to repeat the loop and try again.
#
# When a timeout value is given the thread must be cognizant of time spent
# in the spin loop. The remaining time is checked every loop. When the time
# runs out the thread will exit.
#
# A "node" is the data structure used to perform the exchange. Only the
# occupier's node is necessary. It's the node used for the exchange.
# Each node has an "item," a "hole" (self), and a "latch." The item is the
# node's initial value. It never changes. It's what the fulfiller returns on
# success. The occupier's hole is where the fulfiller put its item. It's the
# item that the occupier returns on success. The latch is used for synchronization.
# Because a thread may act as either an occupier or fulfiller (or possibly
# both in periods of high contention) every thread creates a node when
# the exchange method is first called.
#
# The following steps occur within the spin loop. If any actions fail
# the thread will loop and try again, so long as there is time remaining.
# If time runs out the thread will return CANCEL.
#
# Check the slot for an occupier:
#
# * If the slot is empty try to occupy
# * If the slot is full try to fulfill
#
# Attempt to occupy:
#
# * Attempt to CAS myself into the slot
# * Go to sleep and wait to be woken by a fulfiller
# * If the sleep is successful then the fulfiller completed its happy path
# - Return the value from my hole (the value given by the fulfiller)
# * When the sleep fails (time ran out) attempt to cancel the operation
# - Attempt to CAS myself out of the hole
# - If successful there is no contention
# - Return CANCEL
# - On failure, I am competing with a fulfiller
# - Attempt to CAS my hole to CANCEL
# - On success
# - Let the fulfiller deal with my cancel
# - Return CANCEL
# - On failure the fulfiller has completed its happy path
# - Return th value from my hole (the fulfiller's value)
#
# Attempt to fulfill:
#
# * Attempt to CAS the occupier out of the slot
# - On failure loop again
# * Attempt to CAS my item into the occupier's hole
# - On failure the occupier is trying to cancel
# - Loop again
# - On success we are on the happy path
# - Wake the sleeping occupier
# - Return the occupier's item
value = NULL if value.nil? # The sentinel allows nil to be a valid value
me = Node.new(value) # create my node in case I need to occupy
end_at = Concurrent.monotonic_time + timeout.to_f # The time to give up
result = loop do
other = slot
if other && compare_and_set_slot(other, nil)
# try to fulfill
if other.compare_and_set_value(nil, value)
# happy path
other.latch.count_down
break other.item
end
elsif other.nil? && compare_and_set_slot(nil, me)
# try to occupy
timeout = end_at - Concurrent.monotonic_time if timeout
if me.latch.wait(timeout)
# happy path
break me.value
else
# attempt to remove myself from the slot
if compare_and_set_slot(me, nil)
break CANCEL
elsif !me.compare_and_set_value(nil, CANCEL)
# I've failed to block the fulfiller
break me.value
end
end
end
break CANCEL if timeout && Concurrent.monotonic_time >= end_at
end
result == NULL ? nil : result
end | @!macro exchanger_method_do_exchange
@return [Object, CANCEL] the value exchanged by the other thread; {CANCEL} on timeout | do_exchange | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def do_exchange(value, timeout)
result = nil
if timeout.nil?
Synchronization::JRuby.sleep_interruptibly do
result = @exchanger.exchange(value)
end
else
Synchronization::JRuby.sleep_interruptibly do
result = @exchanger.exchange(value, 1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
end
end
result
rescue java.util.concurrent.TimeoutException
CANCEL
end | @!macro exchanger_method_do_exchange
@return [Object, CANCEL] the value exchanged by the other thread; {CANCEL} on timeout | do_exchange | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/exchanger.rb | Apache-2.0 |
def initialize(opts = {}, &block)
raise ArgumentError.new('no block given') unless block_given?
super(NULL, opts.merge(__task_from_block__: block), &nil)
end | Create a new `Future` in the `:unscheduled` state.
@yield the asynchronous operation to perform
@!macro executor_and_deref_options
@option opts [object, Array] :args zero or more arguments to be passed the task
block on execution
@raise [ArgumentError] if no block is given | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | Apache-2.0 |
def execute
if compare_and_set_state(:pending, :unscheduled)
@executor.post{ safe_execute(@task, @args) }
self
end
end | Execute an `:unscheduled` `Future`. Immediately sets the state to `:pending` and
passes the block to a new thread/thread pool for eventual execution.
Does nothing if the `Future` is in any state other than `:unscheduled`.
@return [Future] a reference to `self`
@example Instance and execute in separate steps
future = Concurrent::Future.new{ sleep(1); 42 }
future.state #=> :unscheduled
future.execute
future.state #=> :pending
@example Instance and execute in one line
future = Concurrent::Future.new{ sleep(1); 42 }.execute
future.state #=> :pending | execute | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | Apache-2.0 |
def cancel
if compare_and_set_state(:cancelled, :pending)
complete(false, nil, CancelledOperationError.new)
true
else
false
end
end | Attempt to cancel the operation if it has not already processed.
The operation can only be cancelled while still `pending`. It cannot
be cancelled once it has begun processing or has completed.
@return [Boolean] was the operation successfully cancelled. | cancel | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | Apache-2.0 |
def cancelled?
state == :cancelled
end | Has the operation been successfully cancelled?
@return [Boolean] | cancelled? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | Apache-2.0 |
def wait_or_cancel(timeout)
wait(timeout)
if complete?
true
else
cancel
false
end
end | Wait the given number of seconds for the operation to complete.
On timeout attempt to cancel the operation.
@param [Numeric] timeout the maximum time in seconds to wait.
@return [Boolean] true if the operation completed before the timeout
else false | wait_or_cancel | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/future.rb | Apache-2.0 |
def initialize(value = NULL, opts = {}, &block)
if value != NULL && block_given?
raise ArgumentError.new('provide only a value or a block')
end
super(&nil)
synchronize { ns_initialize(value, opts, &block) }
end | Create a new `IVar` in the `:pending` state with the (optional) initial value.
@param [Object] value the initial value
@param [Hash] opts the options to create a message with
@option opts [String] :dup_on_deref (false) call `#dup` before returning
the data
@option opts [String] :freeze_on_deref (false) call `#freeze` before
returning the data
@option opts [String] :copy_on_deref (nil) call the given `Proc` passing
the internal value and returning the value returned from the proc | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | Apache-2.0 |
def add_observer(observer = nil, func = :update, &block)
raise ArgumentError.new('cannot provide both an observer and a block') if observer && block
direct_notification = false
if block
observer = block
func = :call
end
synchronize do
if event.set?
direct_notification = true
else
observers.add_observer(observer, func)
end
end
observer.send(func, Time.now, self.value, reason) if direct_notification
observer
end | Add an observer on this object that will receive notification on update.
Upon completion the `IVar` will notify all observers in a thread-safe way.
The `func` method of the observer will be called with three arguments: the
`Time` at which the `Future` completed the asynchronous operation, the
final `value` (or `nil` on rejection), and the final `reason` (or `nil` on
fulfillment).
@param [Object] observer the object that will be notified of changes
@param [Symbol] func symbol naming the method to call when this
`Observable` has changes` | add_observer | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | Apache-2.0 |
def set(value = NULL)
check_for_block_or_value!(block_given?, value)
raise MultipleAssignmentError unless compare_and_set_state(:processing, :pending)
begin
value = yield if block_given?
complete_without_notification(true, value, nil)
rescue => ex
complete_without_notification(false, nil, ex)
end
notify_observers(self.value, reason)
self
end | @!macro ivar_set_method
Set the `IVar` to a value and wake or notify all threads waiting on it.
@!macro ivar_set_parameters_and_exceptions
@param [Object] value the value to store in the `IVar`
@yield A block operation to use for setting the value
@raise [ArgumentError] if both a value and a block are given
@raise [Concurrent::MultipleAssignmentError] if the `IVar` has already
been set or otherwise completed
@return [IVar] self | set | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | Apache-2.0 |
def fail(reason = StandardError.new)
complete(false, nil, reason)
end | @!macro ivar_fail_method
Set the `IVar` to failed due to some error and wake or notify all threads waiting on it.
@param [Object] reason for the failure
@raise [Concurrent::MultipleAssignmentError] if the `IVar` has already
been set or otherwise completed
@return [IVar] self | fail | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | Apache-2.0 |
def try_set(value = NULL, &block)
set(value, &block)
true
rescue MultipleAssignmentError
false
end | Attempt to set the `IVar` with the given value or block. Return a
boolean indicating the success or failure of the set operation.
@!macro ivar_set_parameters_and_exceptions
@return [Boolean] true if the value was set else false | try_set | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/ivar.rb | Apache-2.0 |
def initialize(options = nil, &default_proc)
if options.kind_of?(::Hash)
validate_options_hash!(options)
else
options = nil
end
super(options)
@default_proc = default_proc
end | @param [Hash, nil] options options to set the :initial_capacity or :load_factor. Ignored on some Rubies.
@param [Proc] default_proc Optional block to compute the default value if the key is not set, like `Hash#default_proc` | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def fetch_or_store(key, default_value = NULL)
fetch(key) do
put(key, block_given? ? yield(key) : (NULL == default_value ? raise_fetch_no_key : default_value))
end
end | Fetch value with key, or store default value when key is absent,
or fail when no default_value is given. This is a two step operation,
therefore not atomic. The store can overwrite other concurrently
stored value.
@param [Object] key
@param [Object] default_value
@yield default value for a key
@yieldparam key [Object]
@yieldreturn [Object] default value
@return [Object] the value or default value | fetch_or_store | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def put_if_absent(key, value)
computed = false
result = compute_if_absent(key) do
computed = true
value
end
computed ? nil : result
end | Insert value into map with key if key is absent in one atomic step.
@param [Object] key
@param [Object] value
@return [Object, nil] the previous value when key was present or nil when there was no key | put_if_absent | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def value?(value)
each_value do |v|
return true if value.equal?(v)
end
false
end | Is the value stored in the map. Iterates over all values.
@param [Object] value
@return [true, false] | value? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def keys
arr = []
each_pair { |k, v| arr << k }
arr
end | All keys
@return [::Array<Object>] keys | keys | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def values
arr = []
each_pair { |k, v| arr << v }
arr
end | All values
@return [::Array<Object>] values | values | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def each_key
each_pair { |k, v| yield k }
end | Iterates over each key.
@yield for each key in the map
@yieldparam key [Object]
@return [self]
@!macro map.atomic_method_with_block | each_key | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def each_value
each_pair { |k, v| yield v }
end | Iterates over each value.
@yield for each value in the map
@yieldparam value [Object]
@return [self]
@!macro map.atomic_method_with_block | each_value | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def each_pair
return enum_for :each_pair unless block_given?
super
end | Iterates over each key value pair.
@yield for each key value pair in the map
@yieldparam key [Object]
@yieldparam value [Object]
@return [self]
@!macro map.atomic_method_with_block | each_pair | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def key(value)
each_pair { |k, v| return k if v == value }
nil
end | Find key of a value.
@param [Object] value
@return [Object, nil] key or nil when not found | key | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def empty?
each_pair { |k, v| return false }
true
end | Is map empty?
@return [true, false] | empty? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def size
count = 0
each_pair { |k, v| count += 1 }
count
end | The size of map.
@return [Integer] size | size | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/map.rb | Apache-2.0 |
def just?
! nothing?
end | Is this `Maybe` a `Just` (successfully fulfilled with a value)?
@return [Boolean] True if `Just` or false if `Nothing`. | just? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | Apache-2.0 |
def nothing?
@nothing != NONE
end | Is this `Maybe` a `nothing` (rejected with an exception upon fulfillment)?
@return [Boolean] True if `Nothing` or false if `Just`. | nothing? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | Apache-2.0 |
def or(other)
just? ? just : other
end | Return either the value of self or the given default value.
@return [Object] The value of self when `Just`; else the given default. | or | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | Apache-2.0 |
def initialize(just, nothing)
@just = just
@nothing = nothing
end | Create a new `Maybe` with the given attributes.
@param [Object] just The value when `Just` else `NONE`.
@param [Exception, Object] nothing The exception when `Nothing` else `NONE`.
@return [Maybe] The new `Maybe`.
@!visibility private | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/maybe.rb | Apache-2.0 |
def values_at(*indexes)
synchronize { ns_values_at(indexes) }
end | @!macro struct_values_at
Returns the struct member values for each selector as an Array.
A selector may be either an Integer offset or a Range of offsets (as in `Array#values_at`).
@param [Fixnum, Range] indexes the index(es) from which to obatin the values (in order) | values_at | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | Apache-2.0 |
def inspect
synchronize { ns_inspect }
end | @!macro struct_inspect
Describe the contents of this struct in a string.
@return [String] the contents of this struct in a string | inspect | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | Apache-2.0 |
def merge(other, &block)
synchronize { ns_merge(other, &block) }
end | @!macro struct_merge
Returns a new struct containing the contents of `other` and the contents
of `self`. If no block is specified, the value for entries with duplicate
keys will be that of `other`. Otherwise the value for each duplicate key
is determined by calling the block with the key, its value in `self` and
its value in `other`.
@param [Hash] other the hash from which to set the new values
@yield an options block for resolving duplicate keys
@yieldparam [String, Symbol] member the name of the member which is duplicated
@yieldparam [Object] selfvalue the value of the member in `self`
@yieldparam [Object] othervalue the value of the member in `other`
@return [Synchronization::AbstractStruct] a new struct with the new values
@raise [ArgumentError] of given a member that is not defined in the struct | merge | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mutable_struct.rb | Apache-2.0 |
def initialize(value = EMPTY, opts = {})
@value = value
@mutex = Mutex.new
@empty_condition = ConditionVariable.new
@full_condition = ConditionVariable.new
set_deref_options(opts)
end | Create a new `MVar`, either empty or with an initial value.
@param [Hash] opts the options controlling how the future will be processed
@!macro deref_options | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def try_take!
@mutex.synchronize do
if unlocked_full?
value = @value
@value = EMPTY
@empty_condition.signal
apply_deref_options(value)
else
EMPTY
end
end
end | Non-blocking version of `take`, that returns `EMPTY` instead of blocking. | try_take! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def try_put!(value)
@mutex.synchronize do
if unlocked_empty?
@value = value
@full_condition.signal
true
else
false
end
end
end | Non-blocking version of `put`, that returns whether or not it was successful. | try_put! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def set!(value)
@mutex.synchronize do
old_value = @value
@value = value
@full_condition.signal
apply_deref_options(old_value)
end
end | Non-blocking version of `put` that will overwrite an existing value. | set! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def modify!
raise ArgumentError.new('no block given') unless block_given?
@mutex.synchronize do
value = @value
@value = yield value
if unlocked_empty?
@empty_condition.signal
else
@full_condition.signal
end
apply_deref_options(value)
end
end | Non-blocking version of `modify` that will yield with `EMPTY` if there is no value yet. | modify! | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def empty?
@mutex.synchronize { @value == EMPTY }
end | Returns if the `MVar` is currently empty. | empty? | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/mvar.rb | Apache-2.0 |
def initialize(opts = {}, &block)
opts.delete_if { |k, v| v.nil? }
super(NULL, opts.merge(__promise_body_from_block__: block), &nil)
end | Initialize a new Promise with the provided options.
@!macro executor_and_deref_options
@!macro promise_init_options
@option opts [Promise] :parent the parent `Promise` when building a chain/tree
@option opts [Proc] :on_fulfill fulfillment handler
@option opts [Proc] :on_reject rejection handler
@option opts [object, Array] :args zero or more arguments to be passed
the task block on execution
@yield The block operation to be performed asynchronously.
@raise [ArgumentError] if no block is given
@see http://wiki.commonjs.org/wiki/Promises/A
@see http://promises-aplus.github.io/promises-spec/ | initialize | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promise.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promise.rb | Apache-2.0 |
def execute
if root?
if compare_and_set_state(:pending, :unscheduled)
set_pending
realize(@promise_body)
end
else
compare_and_set_state(:pending, :unscheduled)
@parent.execute
end
self
end | Execute an `:unscheduled` `Promise`. Immediately sets the state to `:pending` and
passes the block to a new thread/thread pool for eventual execution.
Does nothing if the `Promise` is in any state other than `:unscheduled`.
@return [Promise] a reference to `self` | execute | ruby | collabnix/kubelabs | .bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promise.rb | https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promise.rb | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.