Sha256: a4c00afbb708bb2b1fb0d84dad589f87bb8842a7b26d1c1630386955137d7d54

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

require_relative 'client'
require_relative 'repos'
require_relative 'result'
require_relative 'task'

module Kamerling
  class Receiver
    def self.receive(addr:, message:, repos: Repos)
      new(addr: addr, message: message, repos: repos).receive
    end

    def initialize(addr:, message:, repos:)
      @addr, @message, @repos = addr, message, repos
    end

    def receive
      client.busy = false
      task.done   = true
      repos << result << client << task
    end

    attr_reader :addr, :message, :repos
    private     :addr, :message, :repos

    private

    def client
      @client ||= repos[Client][message.client_uuid]
    end

    def result
      Result.new(addr: addr, client: client, data: message.payload, task: task)
    end

    def task
      @task ||= repos[Task][message.task_uuid]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.3 lib/kamerling/receiver.rb