Created
October 24, 2012 11:51
-
-
Save ta/3945672 to your computer and use it in GitHub Desktop.
Fire and Forget in Ruby
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
# -*- 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