class Async::FiberPool
- Async::FiberPool
- Async::Pool
- Reference
- Object
Included Modules
Defined in:
pool/fiber_pool.crConstructors
-
.new(nb_of_workers : Int32, verbose_level = default_severity_level)
Launch a pool, with
nb_of_workers
workers.
Instance Method Summary
-
#finalize
Finish every jobs, currently executed or pending, destroy all workers and the pool itself
-
#finish
Wait for every jobs to finish, and destroy all workers
-
#push(callable, *args)
Add a job to the pool.
-
#stop
Tell the pool to finish all currently executed jobs, then to kill all workers
-
#terminate
Kill instantaneously all workers
-
#wait
Wait for every jobs to finish
-
#wait_for(callable, *args)
Add a job to the pool, and block the execution until this job is done
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
Launch a pool, with nb_of_workers
workers. As it's a fiber pool, each worker is a Fiber
Instance Method Detail
Finish every jobs, currently executed or pending, destroy all workers and the pool itself
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!)
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")
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!)
Kill instantaneously all workers
NOTE The pool is no more available after this
TODO Not implemented yet
Add a job to the pool, and block the execution until this job is done
NOTE Blocking call