class Async::FiberPool

Included Modules

Defined in:

pool/fiber_pool.cr

Constructors

Instance Method Summary

Instance methods inherited from module Async::AsyncLogger

verbose_level=(level : Logger::Severity) verbose_level=

Instance methods inherited from class Async::Pool

finalize finalize, finish finish, push push, stop stop, terminate terminate, wait wait, wait_for wait_for, worker worker

Constructor methods inherited from class Async::Pool

new new

Constructor Detail

def self.new(nb_of_workers : Int32, verbose_level = default_severity_level) #

Launch a pool, with nb_of_workers workers. As it's a fiber pool, each worker is a Fiber


[View source]

Instance Method Detail

def finalize #

Finish every jobs, currently executed or pending, destroy all workers and the pool itself


[View source]
def finish #

Wait for every jobs to finish, and destroy all workers

NOTE Blocking call

NOTE The pool is no more available after this (no worker left!)


[View source]
def push(callable, *args) #

Add a job to the pool. When a worker will be available, it'll pick the job and execute it.

#push takes any type of Proc as argument, and all the arguments to be passed to the proc when it'll be called

Notice that your code won't compile if you forget one argument

Proc without arguments

pool.push(->{ puts "hello" })

Proc with arguments

pool.push(->(i : Int32, str : String) { puts "#{str} : #{i}" }, 12, "Hello, number")

From function

def welcome(name : String)
  puts "Hello, #{name}!"
  name
end

welcome_proc = ->welcome(String)
pool.push(welcome_proc, "John")
# Or simply
pool.push(->welcome(String), "John")

[View source]
def stop #

Tell the pool to finish all currently executed jobs, then to kill all workers

NOTE All the pending queued jobs won't be executed and are lost

NOTE The pool is no more available after this (no worker left!)


[View source]
def terminate #

Kill instantaneously all workers

NOTE The pool is no more available after this

TODO Not implemented yet


[View source]
def wait #

Wait for every jobs to finish

NOTE Blocking call


[View source]
def wait_for(callable, *args) #

Add a job to the pool, and block the execution until this job is done

NOTE Blocking call


[View source]