Class: Task

Inherits:
Object show all
Defined in:
flow/task/task.rb

Defined Under Namespace

Classes: Queue, Timer

Class Method Summary (collapse)

Class Method Details

+ (Object) after(delay, &block)

Schedule a block after a given interval (in seconds)

Examples:

timer = Task.after 0.5 do
  # ...
end


37
38
39
# File 'flow/task/task.rb', line 37

def self.after(delay, &block)
  Task::Timer.new(delay, false, block)
end

+ (Object) background(&block)

Run a block concurrently in the background Blocks will be distributed among a pool of threads and may be executed in parallel.

Examples:

Task.background do
  # ...
end


56
57
58
# File 'flow/task/task.rb', line 56

def self.background(&block)
  Task::Queue.schedule_on_background(block)
end

+ (Timer) every(interval, &block)

Schedule a block at every given interval (in seconds)

Examples:

timer = Task.every 2.5 do
  # ...
end

Returns:



28
29
30
# File 'flow/task/task.rb', line 28

def self.every(interval, &block)
  Task::Timer.new(interval, true, block)
end

+ (Object) main(&block)

Run a block on the main thread

Examples:

Task.main do
  # ...
end


46
47
48
# File 'flow/task/task.rb', line 46

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

+ (Object) main?

Check is the method has been called from the main thread

Examples:

Task.main?


# File 'flow/task/task.rb', line 69

+ (Queue) queue

Create a serial queue A Task::Queue object keeps a reference to a single thread.

Examples:

q = Task.queue

Returns:



65
66
67
# File 'flow/task/task.rb', line 65

def self.queue
  Task::Queue.new
end