Created
February 3, 2016 07:54
-
-
Save kn1kn1/564202800684e362be36 to your computer and use it in GitHub Desktop.
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
# Stops all threads in the current buffer. | |
# @example | |
# load "~/sp-stop-util.rb" | |
# stop_current_buffer | |
# @note This method is using the Sonic Pi's internal methods and variables. | |
# SonicPi::RuntimeMethods#__current_job_info, __stop_job, __current_job_id | |
# SonicPi::Runtime#user_jobs, job_subthreads | |
def stop_current_buffer | |
current_job_info = __current_job_info | |
current_workspace_name = current_job_info[:workspace] || '' | |
puts "current workspace name: #{current_workspace_name}" | |
# find sub threads job id | |
current_buffer_job_ids = Set.new | |
@user_jobs.each_id do |job_id| | |
puts "job_id: #{job_id}" | |
subthreads = @job_subthreads[job_id] | |
next unless subthreads | |
subthreads.each do |st| | |
info = st.thread_variable_get :sonic_pi_spider_job_info || {} | |
puts "info: #{info}" | |
workspace = info[:workspace] | |
puts "workspace name: #{workspace}" | |
current_buffer_job_ids.add job_id if workspace == current_workspace_name | |
end | |
end | |
# kill sub threads | |
current_buffer_job_ids.each do |job_id| | |
__stop_job job_id | |
end | |
# kill current thread at last | |
__stop_job __current_job_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment