Class: Farce::Local::Queue

Inherits:
Abstract::Queue show all
Includes:
Scoped, Shareable::Unfreezable
Defined in:
lib/farce/local/queue.rb

Overview

A shareable queue with independent mutable storage in each scope.

Instance Attribute Summary

Attributes included from Scoped

#scope

Attributes inherited from Abstract::Queue

#capacity, #num_waiting, #size

Instance Method Summary collapse

Methods included from Shareable

#ractor_shareable?

Methods inherited from Abstract::Queue

#age_tracking?, #clear, #close, #closed?, #deq, #duplicable?, #empty?, #enq, #full?, #generation, #length, #max, #oldest_age, #oldest_enqueued_at, #pop, #push, #seal, #sealed?, #try_pop, #try_push, #wait_pop, #wait_push

Constructor Details

#initialize(capacity: 1024, track_age: false, scope: :ractor, **options) ⇒ Queue

Valid scopes are:

  • :ractor - The value is shared by all threads within the same Ractor.
  • :thread_group - The value is shared by all threads within the same thread group.
  • :thread - The value is shared by all fibers within the same thread.
  • :fiber_storage - The value is shared by all fibers using the same storage. Unless explicitly specified, storage is inherited from the parent fiber for blocking fibers, but not for non-blocking fibers (such as those created by Scheduler#schedule).
  • :fiber - Each fiber has its own independent value.

Parameters:

  • capacity (Integer, nil) (defaults to: 1024) —

    the maximum number of values, or nil for an unbounded queue

  • track_age (Boolean) (defaults to: false) —

    whether to track enqueue age and queue generations

  • scope (Symbol) (defaults to: :ractor) —

    the scope of the queue

Options Hash (**options):

  • fiber_wait (:auto, :io, :block) — default: :auto —

    how scheduled fibers wait on CRuby



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/farce/local/queue.rb', line 16

class Queue < Abstract::Queue
  include Shareable::Unfreezable
  include Scoped

  # @return [Symbol] always returns `:local`
  def mode = :local

  # @api private
  def fiber_wait = internal_queue.fiber_wait

  private

  def internal_queue        = scoped_value
  def new_scoped_value(...) = Internal::UnsharedQueue.new(...)
end

Instance Method Details

#mode ⇒ Symbol

Returns always returns :local.

Returns:

  • (Symbol) —

    always returns :local



21
# File 'lib/farce/local/queue.rb', line 21

def mode = :local