Thread without join (ARCH6041)
Esta página aún no está disponible en tu idioma.
Key ruby.async.thread-without-join · Severity warning · Category async
A thread started without a matching join lets the spawning scope exit before the thread finishes. Its work may be cut short and exceptions raised inside it are silently lost.
Incorrect
Section titled “Incorrect”def process_batch(items) items.each do |item| Thread.new { upload(item) } end # method returns; uploads may not finish, errors lostendCorrect
Section titled “Correct”def process_batch(items) threads = items.map do |item| Thread.new { upload(item) } end threads.each(&:join)endKeep each spawned thread in a variable and call join on it before leaving the scope.