Module: Delayer::Extend

### Home Classes Methods

### In Files

- lib/delayer/extend.rb

### Methods

- ::extended
- #busy?
- #empty?
- #expire?
- #register
- #register_remain_hook
- #run
- #run_once
- #size

### Class/Module Index

Quicksearch

- Delayer
- Delayer::AlreadyCanceledError
- Delayer::AlreadyExecutedError
- Delayer::AlreadyRunningError
- Delayer::Error
- Delayer::Extend
- Delayer::InvalidPriorityError
- Delayer::Priority
- Delayer::Priority::Extend
- Delayer::Procedure
- Delayer::TooLate

No matching classes.

# Delayer::Extend

### Attributes

exception[R]
expire[RW]

### Public Class Methods

extended(klass) click to toggle source

    # File lib/delayer/extend.rb, line 7
    def self.extended(klass)
      klass.class_eval do
        @first_pointer = @last_pointer = nil
        @busy = false
        @expire = 0
        @remain_hook = nil
        @exception = nil
        @remain_received = false
        @lock = Mutex.new
      end
    end

### Public Instance Methods

busy?() click to toggle source

Return if some jobs processing now.

#### Args

args

  #### Return

  true if Delayer processing job

    # File lib/delayer/extend.rb, line 68
    def busy?
      @busy
    end

empty?() click to toggle source

Return true if no jobs has.

#### Return

true if no jobs has.

    # File lib/delayer/extend.rb, line 75
    def empty?
      !@first_pointer
    end

expire?() click to toggle source

    # File lib/delayer/extend.rb, line 41
    def expire?
      if defined?(@end_time) and @end_time
        @end_time < Time.new.to_f
      else
        false
      end
    end

register(procedure) click to toggle source

register new job.

#### Args

procedure

  job(Delayer::Procedure)

#### Return

self

    # File lib/delayer/extend.rb, line 95
    def register(procedure)
      lock.synchronize do
        if @last_pointer
          @last_pointer = @last_pointer.break procedure
        else
          @last_pointer = @first_pointer = procedure
        end
        if @remain_hook and not @remain_received
          @remain_received = true
          @remain_hook.call
        end
      end
      self
    end

register_remain_hook() click to toggle source

    # File lib/delayer/extend.rb, line 110
    def register_remain_hook
      @remain_hook = Proc.new
    end

run(current_expire = @expire) click to toggle source

Run registered jobs.

#### Args

current_expire

  expire for processing (secs, 0=unexpired)

#### Return

self

    # File lib/delayer/extend.rb, line 24
    def run(current_expire = @expire)
      if 0 == current_expire
        run_once while not empty?
      else
        @end_time = Time.new.to_f + @expire
        run_once while not(empty?) and @end_time >= Time.new.to_f
        @end_time = nil
      end
      if @remain_hook
        @remain_received = !empty?
        @remain_hook.call if @remain_received
      end
    rescue Exception => e
      @exception = e
      raise e
    end

run_once() click to toggle source

Run a job and forward pointer.

#### Return

self

    # File lib/delayer/extend.rb, line 52
    def run_once
      if @first_pointer
        @busy = true
        procedure = forward
        procedure = forward while @first_pointer and procedure.canceled?
        procedure.run unless procedure.canceled?
      end
    ensure
      @busy = false
    end

size(node = @first_pointer) click to toggle source

Return remain jobs quantity.

#### Return

Count of remain jobs

    # File lib/delayer/extend.rb, line 82
    def size(node = @first_pointer)
      if node
        1 + size(node.next)
      else
        0
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.