Sha256: 0bff675ef5426f325029d735f21c33810140f581d5fd8cb4489301624f61cae1

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require_relative 'thread_pool'

module FFI
  module Libfuse
    # A JobPool is a ThreadPool whose worker threads are consuming from a Queue
    class JobPool
      # Create a Job Pool
      # @param [Hash<Symbol,Object>] options
      #  @see ThreadPool.new
      # @param [Proc] worker the unit of work that will be yielded the scheduled jobs
      def initialize(**options, &worker)
        @jq = Queue.new
        @tp = ThreadPool.new(**options) { (args = @jq.pop) && worker.call(*args) }
      end

      # Schedule a job
      # @param [Array<Object>] args
      # @return [self]
      def schedule(*args)
        @jq.push(args)
        self
      end
      alias << schedule
      alias push schedule

      # Close the JobPool
      # @return [self]
      def close
        @jq.close
        self
      end

      # Join the JobPool
      # @return [self]
      def join(&block)
        @tp.join(&block)
        self
      end

      # @see ThreadPool#list
      def list
        @tp.list
      end

      # @see ThreadPool#group
      def group
        @tp.group
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ffi-libfuse-0.4.1 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.4.0 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.3.4 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.3.3 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.1.0.rc20220550 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.0.1.rctest12 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.0.1.rctest11 lib/ffi/libfuse/job_pool.rb
ffi-libfuse-0.0.1.pre lib/ffi/libfuse/job_pool.rb