Sha256: e0a3b8a781a0c20d3faad52e2934015b570cdef2207125bd882ddbcb4c674dc6

Contents?: true

Size: 883 Bytes

Versions: 9

Compression:

Stored size: 883 Bytes

Contents

class Task
  def self.main?
    NSThread.isMainThread
  end

  class Timer
    def initialize(interval, repeats, block)
      queue = Dispatch::Queue.current
      @timer = Dispatch::Source.timer(interval, interval, 0.0, queue) do |src|
        begin
          block.call
        ensure
          stop unless repeats
        end
      end
    end

    def stop
      if @timer
        @timer.cancel!
        @timer = nil
      end
    end
  end

  class Queue
    @@counter = 0
    def initialize
      @queue = Dispatch::Queue.new("com.hipbyte.flow.queue#{@@counter += 1}")
    end

    def schedule(&block)
      @queue.async(&block)
    end

    def wait
      @queue.sync {}
    end

    def self.schedule_on_main(block)
      Dispatch::Queue.main.async(&block)
    end

    def self.schedule_on_background(block)
      Dispatch::Queue.concurrent.async(&block)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
motion-flow-0.1.8 flow/task/cocoa/task.rb
motion-flow-0.1.7 flow/task/cocoa/task.rb
motion-flow-0.1.6 flow/task/cocoa/task.rb
motion-flow-0.1.5 flow/task/cocoa/task.rb
motion-flow-0.1.4 flow/task/cocoa/task.rb
motion-flow-0.1.3 flow/task/cocoa/task.rb
motion-flow-0.1.2 flow/task/cocoa/task.rb
motion-flow-0.1.1 flow/task/cocoa/task.rb
motion-flow-0.1 flow/task/cocoa/task.rb