class Async::IO::Threads

Public Class Methods

new(parent: nil) click to toggle source
# File lib/async/io/threads.rb, line 28
def initialize(parent: nil)
        @parent = parent
end

Public Instance Methods

async(parent: (@parent or Task.current)) { || ... } click to toggle source
# File lib/async/io/threads.rb, line 33
def async(parent: (@parent or Task.current))
        parent.async do
                thread = ::Thread.new do
                        yield
                end
                
                thread.join
        rescue Stop
                if thread&.alive?
                        thread.raise(Stop)
                end
                
                begin
                        thread.join
                rescue Stop
                        # Ignore.
                end
        end
end