lib/volt/tasks/dispatcher.rb
def dispatch(channel, message)
      callback_id, class_name, method_name, meta_data, *args = message
      method_name = method_name.to_sym

      # Get the class
      klass = Object.send(:const_get, class_name)

      promise = Promise.new

      # Check that we are calling on a TaskHandler class and a method provide at
      # TaskHandler or above in the ancestor chain.
      if safe_method?(klass, method_name)
        promise.resolve(nil)

        # Init and send the method
        promise = promise.then do
          Thread.current['meta'] = meta_data

          result = klass.new(channel, self).send(method_name, *args)

          Thread.current['meta'] = nil

          result
        end

      else
        # Unsafe method
        promise.reject(RuntimeError.new("unsafe method: #{method_name}"))
      end

      if callback_id
        # Run the promise and pass the return value/error back to the client
        promise.then do |result|
          channel.send_message('response', callback_id, result, nil)
        end.fail do |error|
          channel.send_message('response', callback_id, nil, error)
          Volt.logger.error(error)
        end
      end
    end
# Dispatch takes an incoming Task from the client and runs it on the
# server, returning the result to the client.
# Tasks returning a promise will wait to return.
Dispatch takes an incoming Task from the client and runs it on the
server, returning the result to the client.
Tasks returning a promise will wait to return.
Dispatch takes an incoming Task from the client and runs it on the server returning the result to the client . Tasks returning a promise will wait to return .
def dispatch(channel, message)
      callback_id, class_name, method_name, meta_data, *args = message
      method_name = method_name.to_sym
      klass = Object.send(:const_get, class_name)
      promise = Promise.new
      if safe_method?(klass, method_name)
        promise.resolve(nil)
        promise = promise.then do
          Thread.current['meta'] = meta_data
          result = klass.new(channel, self).send(method_name, *args)
          Thread.current['meta'] = nil
          result
        end
      else
        promise.reject(RuntimeError.new("unsafe method: #{method_name}"))
      end
      if callback_id
        promise.then do |result|
          channel.send_message('response', callback_id, result, nil)
        end.fail do |error|
          channel.send_message('response', callback_id, nil, error)
          Volt.logger.error(error)
        end
      end
    end
def dispatch ( channel , message ) callback_id , class_name , method_name , meta_data , * args = message method_name = method_name . to_sym klass = Object . send ( :const_get , class_name ) promise = Promise . new if safe_method? ( klass , method_name ) promise . resolve ( nil ) promise = promise . then do Thread . current [ 'meta' ] = meta_data result = klass . new ( channel , self ) . send ( method_name , * args ) Thread . current [ 'meta' ] = nil result end else promise . reject ( RuntimeError . new ( "unsafe method: #{method_name}" ) ) end if callback_id promise . then do | result | channel . send_message ( 'response' , callback_id , result , nil ) end . fail do | error | channel . send_message ( 'response' , callback_id , nil , error ) Volt . logger . error ( error ) end end end
Dispatch takes an incoming Task from the client and runs it on the
server, returning the result to the client.
Dispatch takes an incoming Task from the client and runs it on the server returning the result to the client .
# Get the class # Check that we are calling on a TaskHandler class and a method provide at # TaskHandler or above in the ancestor chain. # Init and send the method # Unsafe method # Run the promise and pass the return value/error back to the client
channel
message