threadlock 1.3.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/USAGE.rb +6 -0
  3. data/lib/threadlock.rb +17 -8
  4. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33ebf8fec51c4c95030192a3630f9394f67f6d4d
4
- data.tar.gz: 525d769959c4275dcf50c073b5950f076f0b8bcf
3
+ metadata.gz: 5f4d9ebbc0fa0fd4dd7c28101f899614b7819cf4
4
+ data.tar.gz: 9cac3c19d6a2b5506ce1a221011e0b9cb6ef9b3b
5
5
  SHA512:
6
- metadata.gz: 96a12c56eda8fe667a7e5a260e75da6980cffad338bf3415f925164ff94a8cfeca0c73e2336a74d26adca8cbcb5bf2d2978f60a07a432779d223f1b629787da0
7
- data.tar.gz: c93bc456a06b3d38039ba8f7026c24316f50c4f91d0b2b19c397133d740fa7c18aafd6abe5d02105851a001fc05d146650fa966540718df253b3145ceda263ac
6
+ metadata.gz: 0071aa7664651818f98bb1f53100d4c1d3bb996c5f3fa2c5bf09e01787d94991f8bc7affedc73ac88ba0e4b3baa5103c1dfa6365dc87ffd399d0bc0c32fdf41e
7
+ data.tar.gz: cd58382a5f462ebd020ee8b24c8506cc85bdf4aa98ed26eb88e5f6b0aa5c3402084f9bb0d0607e60ac56569ff30d0a4aeda29ffd0e4e4d3e56538d2391133612
data/USAGE.rb CHANGED
@@ -3,6 +3,7 @@ require 'threadlock'
3
3
 
4
4
 
5
5
  class Example1
6
+ include Threadlock
6
7
 
7
8
  def foo
8
9
  @foo = true
@@ -28,6 +29,7 @@ end
28
29
 
29
30
 
30
31
  class Example2
32
+ include Threadlock
31
33
 
32
34
  def foo
33
35
  @foo = true
@@ -52,6 +54,7 @@ end
52
54
 
53
55
 
54
56
  class Example3
57
+ include Threadlock
55
58
 
56
59
  def foo
57
60
  @foo = true
@@ -76,6 +79,7 @@ end
76
79
 
77
80
 
78
81
  class Example4
82
+ include Threadlock
79
83
 
80
84
  def foo
81
85
  @foo = true
@@ -101,6 +105,7 @@ end
101
105
 
102
106
 
103
107
  class Example5
108
+ include Threadlock
104
109
 
105
110
  def initialize
106
111
  @custom_lock_name = Mutex.new
@@ -129,6 +134,7 @@ end
129
134
 
130
135
 
131
136
  class Example6 # Ruby 2.1 only
137
+ include Threadlock
132
138
 
133
139
  # Ruby 2.1 only: wrap new method foo in a re-entrant lock
134
140
  threadlock def foo
@@ -1,14 +1,23 @@
1
+
1
2
  require 'monitor'
2
3
 
3
- def threadlock(*meths, lock: :@___threadlock___)
4
- meths.flatten.each do |meth|
5
- m = instance_method(meth)
6
- define_method(meth) do |*args, &block|
7
- (instance_variable_get(lock) or \
8
- instance_variable_set(lock, Monitor.new))
9
- .synchronize do
10
- m.bind(self).call(*args, &block)
4
+ module Threadlock
5
+
6
+ def self.included(mod)
7
+ mod.extend Threadlock
8
+ end
9
+
10
+ def threadlock(*meths, lock: :@___threadlock___)
11
+ meths.flatten.each do |meth|
12
+ m = instance_method(meth)
13
+ define_method(meth) do |*args, &block|
14
+ (instance_variable_get(lock) or \
15
+ instance_variable_set(lock, Monitor.new))
16
+ .synchronize do
17
+ m.bind(self).call(*args, &block)
18
+ end
11
19
  end
12
20
  end
13
21
  end
22
+
14
23
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threadlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe McIlvain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-06 00:00:00.000000000 Z
11
+ date: 2013-12-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'Use the threadlock function in your class definition to automatically
13
+ description: "Use the threadlock method in your class definition to automatically
14
14
  run instance methods inside of an instance-wide re-entrant lock (Monitor). All
15
- locked methods in an instance are protect by a single lock. You can protect all
16
- or some of your methods from being run asynchronously. In Ruby>=2.1, threadlock
17
- can also be syntactically used as a decorator. '
15
+ locked methods in an instance are protected by a single lock, unless a specific
16
+ lock is specified. You can protect all or some of your methods from being run concurrently.
17
+ \ In Ruby>=2.1, threadlock can also be used as a syntactic decorator. \n Enjoy."
18
18
  email: joe.eli.mac@gmail.com
19
19
  executables: []
20
20
  extensions: []
@@ -50,3 +50,4 @@ signing_key:
50
50
  specification_version: 4
51
51
  summary: 'threadlock: Easy, featherweight thread protection for basic ruby objects.'
52
52
  test_files: []
53
+ has_rdoc: