Class: Tina4::Background::Task
- Inherits:
-
Object
- Object
- Tina4::Background::Task
- Defined in:
- lib/tina4/background.rb
Overview
Handle for one registered background task — the ONE background surface,
identical across the four frameworks: a handle with a boolean stop plus a
count. Mirrors Python's BackgroundTask (handle.stop()), PHP's
Tina4\BackgroundTask ($handle->stop()) and Node's background() handle
(handle.stop()).
It also answers [:callback]/[:interval]/[:thread]/[:running] (read
AND write) so a descriptor and a handle are the same object — code that
introspected the old Hash descriptor keeps working unchanged.
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#running ⇒ Object
Returns the value of attribute running.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style read, so
task[:thread]/task[:running]still work. -
#[]=(key, value) ⇒ Object
Hash-style write, so the scheduler's
task[:thread] = ...still works. -
#initialize(callback, interval) ⇒ Task
constructor
A new instance of Task.
-
#running? ⇒ Boolean
True while the task is registered and ticking.
-
#stop(timeout: 2.0) ⇒ Boolean
Stop this task and DEREGISTER it.
-
#stopped? ⇒ Boolean
True once stop has run (the task is no longer running).
Constructor Details
#initialize(callback, interval) ⇒ Task
Returns a new instance of Task.
31 32 33 34 35 36 |
# File 'lib/tina4/background.rb', line 31 def initialize(callback, interval) @callback = callback @interval = interval @thread = nil @running = false end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
29 30 31 |
# File 'lib/tina4/background.rb', line 29 def callback @callback end |
#interval ⇒ Object
Returns the value of attribute interval.
29 30 31 |
# File 'lib/tina4/background.rb', line 29 def interval @interval end |
#running ⇒ Object
Returns the value of attribute running.
29 30 31 |
# File 'lib/tina4/background.rb', line 29 def running @running end |
#thread ⇒ Object
Returns the value of attribute thread.
29 30 31 |
# File 'lib/tina4/background.rb', line 29 def thread @thread end |
Instance Method Details
#[](key) ⇒ Object
Hash-style read, so task[:thread] / task[:running] still work.
58 59 60 61 62 63 64 65 |
# File 'lib/tina4/background.rb', line 58 def [](key) case key when :callback then @callback when :interval then @interval when :thread then @thread when :running then @running end end |
#[]=(key, value) ⇒ Object
Hash-style write, so the scheduler's task[:thread] = ... still works.
68 69 70 71 72 73 74 75 |
# File 'lib/tina4/background.rb', line 68 def []=(key, value) case key when :callback then @callback = value when :interval then @interval = value when :thread then @thread = value when :running then @running = value end end |
#running? ⇒ Boolean
Returns true while the task is registered and ticking.
53 54 55 |
# File 'lib/tina4/background.rb', line 53 def running? @running end |
#stop(timeout: 2.0) ⇒ Boolean
Stop this task and DEREGISTER it. Idempotent — a second call is a safe no-op that returns false.
43 44 45 |
# File 'lib/tina4/background.rb', line 43 def stop(timeout: 2.0) Background.stop_task(self, timeout: timeout) end |
#stopped? ⇒ Boolean
Returns true once stop has run (the task is no longer running).
48 49 50 |
# File 'lib/tina4/background.rb', line 48 def stopped? !@running end |