thread 0.0.6.1 → 0.0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3ff37def7bb5f33d4edbfe721d2fd4ed76736c8
4
- data.tar.gz: da06d07f29d4da2ad5ae0c965dd3b857ea2f4693
3
+ metadata.gz: c934f1f9fc550daf4578bd312a80851a7ea76074
4
+ data.tar.gz: 2d678d694a58381d2f197b902341f213c1b887cb
5
5
  SHA512:
6
- metadata.gz: ee229921f532e80cdcbccd1c3f68222b61b262e2bb46ecd0c47a149a5a37d43015705066108ca8a190b7d400b63a9b8be4ac1479669817e02e735cad876c77a0
7
- data.tar.gz: 905962ca00d67d8acbc8eaefcc5be048da9fe799fb0a7f8cc1aa4fbd3c0e52dd88b61a30e9bf175c83dd7625a6bab3428978adb5fb0e9ea4661724185f281a82
6
+ metadata.gz: 9d33610502d9bfc7630b03265743c9fcb5459d115553512b36f41e7d800077a08c96fc79de451c9a5a4f58cca47b7d17a70720e2f7a3d77b201a4eb8ccb9953b
7
+ data.tar.gz: 555dee244c8984b1d8e5ee58f68bebeb12784872eb40b3a48fe6ea6dcaa42b75206dc19baf93967a13dcd2b738de717a32987a8c2bcee9b43686ff682404cb3a
data/lib/thread/future.rb CHANGED
@@ -16,12 +16,13 @@ require 'thread'
16
16
  class Thread::Future
17
17
  Cancel = Class.new(Exception)
18
18
 
19
- # Create a future with the passed block.
20
- def initialize (&block)
19
+ # Create a future with the passed block and optionally using the passed pool.
20
+ def initialize (pool = nil, &block)
21
21
  raise ArgumentError, 'no block given' unless block
22
22
 
23
- @mutex = Mutex.new
24
- @thread = Thread.new {
23
+ @mutex = Mutex.new
24
+
25
+ task = proc {
25
26
  begin
26
27
  deliver block.call
27
28
  rescue Exception => e
@@ -30,6 +31,8 @@ class Thread::Future
30
31
  deliver nil
31
32
  end
32
33
  }
34
+
35
+ @thread = pool ? pool.process(&task) : Thread.new(&task)
33
36
  end
34
37
 
35
38
  # Check if an exception has been raised.
@@ -131,14 +134,14 @@ end
131
134
 
132
135
  class Thread
133
136
  # Helper to create a future
134
- def self.future (&block)
135
- Thread::Future.new(&block)
137
+ def self.future (pool = nil, &block)
138
+ Thread::Future.new(pool, &block)
136
139
  end
137
140
  end
138
141
 
139
142
  module Kernel
140
143
  # Helper to create a future.
141
- def future (&block)
142
- Thread::Future.new(&block)
144
+ def future (pool = nil, &block)
145
+ Thread::Future.new(pool, &block)
143
146
  end
144
147
  end
data/lib/thread/pool.rb CHANGED
@@ -69,6 +69,11 @@ class Thread::Pool
69
69
  @thread = nil
70
70
  end
71
71
 
72
+ # Raise an exception in the thread used by the task.
73
+ def raise (exception)
74
+ @thread.raise(exception)
75
+ end
76
+
72
77
  # Terminate the exception with an optionally given exception.
73
78
  def terminate! (exception = Asked)
74
79
  return if terminated? || finished? || timeout?
@@ -77,7 +82,7 @@ class Thread::Pool
77
82
 
78
83
  return unless running?
79
84
 
80
- @thread.raise exception
85
+ self.raise exception
81
86
  end
82
87
 
83
88
  # Force the task to timeout.
data/thread.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new {|s|
2
2
  s.name = 'thread'
3
- s.version = '0.0.6.1'
3
+ s.version = '0.0.6.2'
4
4
  s.author = 'meh.'
5
5
  s.email = 'meh@schizofreni.co'
6
6
  s.homepage = 'http://github.com/meh/ruby-thread'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thread
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.1
4
+ version: 0.0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meh.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2013-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec