Module: Threaded
- Extended by:
- Threaded
- Included in:
- Threaded
- Defined in:
- lib/threaded.rb,
lib/threaded/errors.rb,
lib/threaded/master.rb,
lib/threaded/worker.rb,
lib/threaded/promise.rb,
lib/threaded/timeout.rb,
lib/threaded/version.rb
Defined Under Namespace
Modules: Timeout
Classes: Master, NoWorkersError, Promise, Worker, WorkerNotStarted
Constant Summary
collapse
- STOP_TIMEOUT =
10
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#inline ⇒ Object
Also known as:
inline?
Returns the value of attribute inline.
11
12
13
|
# File 'lib/threaded.rb', line 11
def inline
@inline
end
|
#logger ⇒ Object
Returns the value of attribute logger.
11
12
13
|
# File 'lib/threaded.rb', line 11
def logger
@logger
end
|
#size ⇒ Object
Returns the value of attribute size.
11
12
13
|
# File 'lib/threaded.rb', line 11
def size
@size
end
|
#timeout ⇒ Object
Returns the value of attribute timeout.
11
12
13
|
# File 'lib/threaded.rb', line 11
def timeout
@timeout
end
|
Instance Method Details
22
23
24
25
26
27
|
# File 'lib/threaded.rb', line 22
def configure(&block)
raise "Queue is already started, must configure queue before starting" if started?
@mutex.synchronize do
yield self
end
end
|
#enqueue(job, *args) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/threaded.rb', line 56
def enqueue(job, *args)
if inline?
job.call(*args)
else
master.enqueue(job, *args)
end
return true
end
|
#master(options = {}) ⇒ Object
Also known as:
master=
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/threaded.rb', line 39
def master(options = {})
@mutex.synchronize do
return @master if @master
self.logger = options[:logger] if options[:logger]
self.size = options[:size] if options[:size]
self.timeout = options[:timeout] if options[:timeout]
@master = Master.new(logger: self.logger,
size: self.size,
timeout: self.timeout)
end
end
|
#start(options = {}) ⇒ Object
16
17
18
19
20
|
# File 'lib/threaded.rb', line 16
def start(options = {})
self.master = options
self.master.start
return self
end
|
#started? ⇒ Boolean
30
31
32
33
|
# File 'lib/threaded.rb', line 30
def started?
return false unless master
master.alive?
end
|
#stop(timeout = STOP_TIMEOUT) ⇒ Object
65
66
67
68
69
|
# File 'lib/threaded.rb', line 65
def stop(timeout = STOP_TIMEOUT)
return true unless master
master.stop(timeout)
return true
end
|
#stopped? ⇒ Boolean
35
36
37
|
# File 'lib/threaded.rb', line 35
def stopped?
!started?
end
|