lib/bolt/executor.rb
# Execute a plan function concurrently. This function accepts the executor
# function to be run and the parameters to pass to it, and returns the
# result of running the executor function.
#
Execute a plan function concurrently. This function accepts the executor
function to be run and the parameters to pass to it, and returns the
result of running the executor function.
Execute a plan function concurrently . This function accepts the executor function to be run and the parameters to pass to it and returns the result of running the executor function .
def run_in_thread
      require 'concurrent'
      require 'fiber'
      future = Concurrent::Future.execute do
        yield
      end
      still_running = 0
      while future.incomplete?
        still_running += 1
        Fiber.yield(still_running < 2 ? :something_happened : :returned_immediately)
      end
      future.value || future.reason
    end
def run_in_thread require 'concurrent' require 'fiber' future = Concurrent :: Future . execute do yield end still_running = 0 while future . incomplete? still_running += 1 Fiber . yield ( still_running < 2 ? :something_happened : :returned_immediately ) end future . value || future . reason end
Execute a plan function concurrently.
Execute a plan function concurrently .
# Used to track how often we resume the same executor function # While the thread is still running # If the Fiber gets resumed, increment the resume tracker. This means # the tracker starts at 1 since it needs to increment before yielding, # since it can't yield then increment. # If the Fiber has been resumed before, still_running will be 2 or # more. Yield different values for when the same Fiber is resumed # multiple times and when it's resumed the first time in order to know # if progress was made in the plan. # Once the thread completes, return the result.