Skip to content

Instantly share code, notes, and snippets.

@ta
Created October 24, 2012 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ta/3945672 to your computer and use it in GitHub Desktop.
Save ta/3945672 to your computer and use it in GitHub Desktop.
Fire and Forget in Ruby
# -*- encoding: utf-8; mode: ruby; tab-width: 2; indent-tabs-mode: nil -*-
def fire_and_forget &block
raise ::LocalJumpError, "No block given" unless block_given?
Process.detach(fork &block)
end
# Demo
puts "main"
fire_and_forget do
sleep 2
puts "fork"
end
puts "main"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment