Sha256: f9ae4dfb251593df361e1f3cdad90613f186009590756d4c579adb0c408e5fed
Contents?: true
Size: 1.49 KB
Versions: 6
Compression:
Stored size: 1.49 KB
Contents
# Copyright © 2011 Preston Lee Ventures, LLC. All rights reserved. # # Preston Lee <preston.lee@prestonlee.com> require 'journeta/logger' module Journeta # See Journeta::Engine class Asynchronous include Logger attr_accessor :thread, :engine def initialize(engine) @engine = engine @thread_lock = Mutex.new @thread = nil end # Start the +Thread+ for this instance, iff not already running. def start @thread_lock.synchronize do if @thread # Do not restart it. else putsd "Creating asynchronous thread for I/O: #{self.class.to_s}." @thread = Thread.new { go } end end end # This method is intentionally not present because it would be of no real value. By the time a boolean is returned, the instance could be in a totally different state. # def started # stopped = true # @thread_lock.synchronize do # stopped = @thread.nil? # end # return stopped # end # Stop the +Thread+ associated with this instance, iff not already stopped. def stop @thread_lock.synchronize do if @thread Thread.kill(@thread) # nasty pants! @thread.join @thread = nil end end end # Abstract thread logic method which must be implemented by the sub-class. def go raise NotImplementedException end end end
Version data entries
6 entries across 6 versions & 1 rubygems