Module: Clack::Prompts::Spinner::Registry Private
- Defined in:
- lib/clack/prompts/spinner.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Running spinners, so the process-exit hook can finish them. A module rather than class-level state so reek counts its ivars separately.
Lock order: a spinner calls Registry.register/Registry.unregister while holding its own mutex (membership changes with the state flip), so the registry mutex nests inside a spinner mutex and never the reverse. Registry.abandon_active snapshots the list and releases the registry mutex before calling any spinner.
Class Method Summary collapse
-
.abandon_active(exception = nil) ⇒ nil
private
Finish every running spinner as abandoned (see Spinner#abandon).
-
.active ⇒ Array<Spinner>
private
Snapshot of running spinners.
-
.register(spinner) ⇒ nil
private
Track a spinner that just started; installs the exit hook on first use.
-
.unregister(spinner) ⇒ nil
private
Forget a spinner that finished or was cleared.
Class Method Details
.abandon_active(exception = nil) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finish every running spinner as abandoned (see Spinner#abandon). A spinner whose output stream fails (closed, EPIPE at exit) is reported with Kernel#warn and the rest are still finished.
95 96 97 98 99 100 101 102 |
# File 'lib/clack/prompts/spinner.rb', line 95 def abandon_active(exception = nil) active.each do |spinner| spinner.abandon(exception) rescue => error warn_failure(error) end nil end |
.active ⇒ Array<Spinner>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns snapshot of running spinners.
66 |
# File 'lib/clack/prompts/spinner.rb', line 66 def active = @mutex.synchronize { @active.dup } |
.register(spinner) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Track a spinner that just started; installs the exit hook on first use.
72 73 74 75 76 77 78 |
# File 'lib/clack/prompts/spinner.rb', line 72 def register(spinner) @mutex.synchronize do install_exit_hook @active << spinner unless @active.include?(spinner) end nil end |
.unregister(spinner) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Forget a spinner that finished or was cleared.
84 85 86 87 |
# File 'lib/clack/prompts/spinner.rb', line 84 def unregister(spinner) @mutex.synchronize { @active.delete(spinner) } nil end |