module Strum::Internal::Component
Public Class Methods
new(type)
click to toggle source
Each component has it's own Reactor(executor) for async tasks.
# File lib/strum/internal/component.rb, line 13 def initialize(type) self[:type] = type case type when :Container self[:Executor] = Async::Container::Controller.new report "Spawned #{class_name} executor!" when :Reactor self[:Executor] = Async::Reactor.new report "Spawned #{class_name} executor!" else self[:Executor] = Async::Reactor.new report "No component_type specified! Defaulted executor to Reactor type for #{class_name}!" end end
Public Instance Methods
asynchronously(&block)
click to toggle source
Executes an Asynchronous task.
# File lib/strum/internal/component.rb, line 30 def asynchronously(&block) raise Strum::Errors::NilAsyncBlock unless block_given? task = Async::Task.current task.sleep(0.0005) task.async { block.call(self) } end
hook(type, receiver)
click to toggle source
Hooks a receiver object to this component. @param type [Symbol] the type of object @param receiver [Object] the receiver we're hooking.
# File lib/strum/internal/component.rb, line 49 def hook(type, receiver) self[type] = receiver end
report(*lines)
click to toggle source
Allow the children to use it. @param lines [Array] lines of text that will be reported by the logger.
# File lib/strum/internal/component.rb, line 56 def report(*lines) lines.each { |line| Strum::LOG.info "[#{self.class.name.split('::').last.to_sym}] 🢐(#{line})" } nil end
tranquilize(duration)
click to toggle source
Puts the current Task to sleep for specified time (Poor name?) @param duration [Numeric] - How long should this task sleep for?
# File lib/strum/internal/component.rb, line 41 def tranquilize(duration) Async::Task.current.sleep(duration) end
Private Instance Methods
execute_task() { |task| ... }
click to toggle source
Executes a task using this component's executor.
# File lib/strum/internal/component.rb, line 65 def execute_task(&block) raise Strum::Errors::NilBlockInvocation.new unless block_given? self[:Executor].run { Async { |task| yield(task) } } self[:Executor].wait if self[:type] == :Container self[:Executor].stop if self[:Executor] end