Sha256: ea1d5997d1d5c2487b5fffcfad4b31f03e9a557a8271b9d893c3803e153805cf

Contents?: true

Size: 656 Bytes

Versions: 5

Compression:

Stored size: 656 Bytes

Contents

# not ready yet

module Threadesque
  class SafeYielder
    
    def self.for_current
      new(Thread.current)
    end
    
    def initialize(thread)
      raise 'not ready yet'
      @thread = thread
      @state = :running
    end
    
    def resume
      raise 'Thread is not sleeping' unless @state == :sleeping
      :wait until @thread.status == 'sleep'
      @state = :running
      @thread.run
      nil
    end
    
    def yield
      raise 'can only stop current Thread' unless Thread.current == @thread
      @state = :sleeping
      loop do
        Thread.stop
        redo if @state == :sleeping
      end
      nil
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quack_concurrency-0.5.4 lib/quack_concurrency/yielder.rb
quack_concurrency-0.5.3 lib/quack_concurrency/yielder.rb
quack_concurrency-0.5.2 lib/quack_concurrency/yielder.rb
quack_concurrency-0.5.1 lib/quack_concurrency/yielder.rb
quack_concurrency-0.5.0 lib/quack_concurrency/yielder.rb