ref: 2eebe5d9f9511c34cb90bf6852d01c42a60a66c2
parent: 06f3e2952573fc39657726c6d84e5e3b33939abc
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Wed Jul 19 13:06:15 EDT 2023
Concurrent and new Test For That Added
--- a/Test_Multi_Threading.rb
+++ b/Test_Multi_Threading.rb
@@ -1,4 +1,24 @@
require 'thread'
+require 'concurrent'
+
+executor = Concurrent::ThreadPoolExecutor.new(
+ min_threads: 2,
+ max_threads: 5,
+ max_queue: 10
+)
+
+futures = []
+
+5.times do |i|
+ futures << Concurrent::Future.execute(executor: executor) do
+ puts "Async task #{i} started"
+ sleep(rand(1..5))
+ puts "Async task #{i} finished"
+ end
+end
+
+futures.each(&:wait)
+executor.shutdown
# Define a method that performs some asynchronous task
def async_task(name)