-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of multi registration in threaded env
- Loading branch information
1 parent
99ff64a
commit 6c4ffb5
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../lib/tty-spinner' | ||
|
||
def spinner_options | ||
[ | ||
":spinner \e[1mNo\e[0m :number Row :line", | ||
format: :dots, | ||
error_mark: '✖', | ||
success_mark: "\e[1m\e[32m✓\e[0m\e[0m" | ||
] | ||
end | ||
|
||
spinners = TTY::Spinner::Multi.new(*spinner_options) | ||
threads = [] | ||
|
||
20.times do |i| | ||
threads << Thread.new do | ||
spinner = spinners.register(*spinner_options) | ||
sleep Random.rand(0.1..0.3) | ||
|
||
10.times do | ||
sleep Random.rand(0.1..0.3) | ||
spinner.update(number: "(#{i})", line: spinner.row) | ||
spinner.spin | ||
end | ||
end | ||
end | ||
|
||
threads.each(&:join) |