robustthread 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/robustthread.rb +34 -0
- metadata +53 -0
data/lib/robustthread.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# This module allows for the creation of a thread that will not simply die when
|
2
|
+
# the process dies. Instead, it joins all RobustThreads in Ruby's exit handler.
|
3
|
+
#
|
4
|
+
# Author:: Jared Kuolt (mailto:me@superjared.com)
|
5
|
+
# Copyright:: Copyright (c) 2009 Jared Kuolt
|
6
|
+
# License:: MIT License
|
7
|
+
|
8
|
+
module RobustThread
|
9
|
+
# Usage:
|
10
|
+
#
|
11
|
+
# RobustThread.new(args) do |x, y|
|
12
|
+
# do_something(x, y)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
def new(*args, &block)
|
16
|
+
thread = Thread.new(*args) do |*targs|
|
17
|
+
block.call(*targs)
|
18
|
+
end
|
19
|
+
thread[:real_ultimate_power] = true
|
20
|
+
thread
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :new
|
24
|
+
end
|
25
|
+
|
26
|
+
# We define the BEGUN constant only after we've setup the exit handler
|
27
|
+
unless defined? RobustThread::BEGUN
|
28
|
+
at_exit do
|
29
|
+
Thread.list.each do |thread|
|
30
|
+
thread.join if thread[:real_ultimate_power]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
RobustThread::BEGUN = true
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robustthread
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Kuolt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Trivial module that allows you to create threads that are not killed if the process exits cleanly
|
17
|
+
email: me@superjared.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/robustthread.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://github.com/JaredKuolt/robustthread/tree/master
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
rubyforge_project: robustthread
|
48
|
+
rubygems_version: 1.3.1
|
49
|
+
signing_key:
|
50
|
+
specification_version: 2
|
51
|
+
summary: Threads that stay alive
|
52
|
+
test_files: []
|
53
|
+
|