Sha256: 3fa4da00b51422e66fd7c1d48234f77f74c4ce844aeb1664f5e0cd50fe9411d3

Contents?: true

Size: 674 Bytes

Versions: 9

Compression:

Stored size: 674 Bytes

Contents

# frozen_string_literal: true

require_relative "../hooks/hook_storage"

module Kanal
  module Core
    module Helpers
      class Queue
        include Hooks

        attr_reader :hooks

        def initialize
          @items = []
          @hooks = HookStorage.new
          hooks.register(:item_queued) # args arguments: item
        end

        def enqueue(element)
          @items.append element
          @hooks.call :item_queued, element
        end

        def dequeue
          @items.shift
        end

        def empty?
          @items.empty?
        end

        def remove(element)
          @items.delete(element)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kanal-0.8.0 lib/kanal/core/helpers/queue.rb
kanal-0.7.0 lib/kanal/core/helpers/queue.rb
kanal-0.6.0 lib/kanal/core/helpers/queue.rb
kanal-0.5.1 lib/kanal/core/helpers/queue.rb
kanal-0.5.0 lib/kanal/core/helpers/queue.rb
kanal-0.4.3 lib/kanal/core/helpers/queue.rb
kanal-0.4.2 lib/kanal/core/helpers/queue.rb
kanal-0.4.1 lib/kanal/core/helpers/queue.rb
kanal-0.4.0 lib/kanal/core/helpers/queue.rb