Skip to content

Commit

Permalink
Add execute_job and close issue #24
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Aug 9, 2017
1 parent 5e56886 commit c5d46fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/tty/spinner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ def job(&work)
end
end

# Execute this spinner job
#
# @api public
def execute_job
if job.arity.zero?
instance_eval(&job)
else
job.(self)
end
end

# Check if this spinner has a scheduled job
#
# @return [Boolean]
Expand Down Expand Up @@ -268,9 +279,10 @@ def resume
#
# @api public
def run(stop_message = '', &block)
job(&block)
auto_spin

@work = Thread.new { instance_eval(&block) }
@work = Thread.new { execute_job }
@work.join
ensure
stop(stop_message)
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/spinner/multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def auto_spin
@spinners.each do |spinner|
if spinner.job?
spinner.auto_spin
jobs << Thread.new { spinner.instance_eval(&spinner.job) }
jobs << Thread.new { spinner.execute_job }
end
end
jobs.each(&:join)
Expand Down

0 comments on commit c5d46fb

Please sign in to comment.