Class: Farce::Local::PriorityQueue

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

Overview

A shareable priority queue with independent mutable storage in each scope.

Instance Attribute Summary

Attributes included from Scoped

#scope

Attributes inherited from Abstract::PriorityQueue

#default_priority, #order

Attributes inherited from Abstract::Queue

#capacity, #num_waiting, #size

Instance Method Summary collapse

Methods included from Shareable

#ractor_shareable?

Methods inherited from Abstract::PriorityQueue

#delete, #first_priority, #last_priority, #peek, #pop, #push, #try_pop, #try_push, #wait_pop

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: nil, default_priority: 0, order: :ascending, scope: :ractor, track_age: false) ⇒ PriorityQueue

Returns a new instance of PriorityQueue.

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: nil) —

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

  • default_priority (BasicObject) (defaults to: 0) —

    the shareable priority used when none is passed to push or try_push

  • order (:ascending, :descending) (defaults to: :ascending) —

    the priority order

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

    the scope of the priority queue

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

    whether to track enqueue age and queue generations

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

    how scheduled fibers wait on CRuby



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/farce/local/priority_queue.rb', line 21

def initialize(
  capacity: nil, default_priority: 0, order: :ascending, scope: :ractor,
  track_age: false, fiber_wait: :auto
)
  unless Ractor.shareable?(default_priority)
    raise Ractor::IsolationError, "default_priority must be Ractor-shareable"
  end

  @order            = normalize_order(order)
  @default_priority = default_priority
  @reverse_order    = @order == :descending
  super(capacity:, scope:, track_age:, fiber_wait:)
end

Instance Method Details

#mode ⇒ Symbol

Returns always returns :local.

Returns:

  • (Symbol) —

    always returns :local



36
# File 'lib/farce/local/priority_queue.rb', line 36

def mode = :local