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

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.

Parameters:

  • exception (Exception, nil) (defaults to: nil)

    the exception ending the process, typically $!

Returns:

  • (nil)


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

.activeArray<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.

Returns:

  • (Array<Spinner>)

    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.

Parameters:

Returns:

  • (nil)


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.

Parameters:

Returns:

  • (nil)


84
85
86
87
# File 'lib/clack/prompts/spinner.rb', line 84

def unregister(spinner)
  @mutex.synchronize { @active.delete(spinner) }
  nil
end