Skip to content

Instantly share code, notes, and snippets.

@prikha
Forked from ta/fire_and_forget.rb
Last active January 23, 2018 16:37
Show Gist options
  • Save prikha/d99aa684b5d95074a15d224da84c0420 to your computer and use it in GitHub Desktop.
Save prikha/d99aa684b5d95074a15d224da84c0420 to your computer and use it in GitHub Desktop.
Fire and Forget in Ruby
def ff! &block
raise ::LocalJumpError, "No block given" unless block_given?
Process.detach(fork &block)
end
# Demo
def test_ff
puts "start"
(1..100).each do |i|
puts i
ff! do
puts "callback #{i}"
end
end
puts "end"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment