Sha256: df3e55ef142922db392a84c6fcaf80f3164ee444dd90d2d79030c21485323e2c

Contents?: true

Size: 488 Bytes

Versions: 4

Compression:

Stored size: 488 Bytes

Contents

# frozen_string_literal: true

export :process

Exceptions = import('./exceptions')

def process(&block)
  watcher = Gyro::Async.new
  thread = Thread.new { run_in_thread(watcher, &block) }
  watcher.await
ensure
  thread.kill if thread.alive?
end

# Runs the given block, passing the result or exception to the given context
# @param ctx [Hash] context
# @return [void]
def run_in_thread(watcher)
  result = yield
  watcher.signal!(result)
rescue Exception => e
  watcher.signal!(e)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
polyphony-0.26 lib/polyphony/core/thread.rb
polyphony-0.25 lib/polyphony/core/thread.rb
polyphony-0.24 lib/polyphony/core/thread.rb
polyphony-0.23 lib/polyphony/core/thread.rb