promise_pool 0.9.0 → 0.9.1

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
- SHA1:
3
- metadata.gz: 8cdae0e0cfd7f377206d08c5898bc2637a4eca77
4
- data.tar.gz: a7a4f91c93b6b81fa4c1472772d445b43ff2764e
2
+ SHA256:
3
+ metadata.gz: d7d935d5301e4c9b26509720e19768c6c041f17daff13f3a2253e1e568062018
4
+ data.tar.gz: 3fe5c84f8a1b85779e8f43486f8b54b4c1705cdaa1400c170e5aaa298b2a7a05
5
5
  SHA512:
6
- metadata.gz: 9d0c873467132e5132e83ecb6f000baed9acc44c282fe02b39455f56a3b6db6222803f65e82e12501e5c7f717c683166bbcfb917a4101736610ceb43bbc98e9d
7
- data.tar.gz: 1143bb7a1a4438909b3efe14471012638168cb920a18d00d6644aeafe0ad4652d6e904f33023b97adcc90b66a5c6652d56bb13f5c0714ea10cb88fc25d49e1f7
6
+ metadata.gz: 2a271da072dd2dcd6819b2e0ca3a70e264e469c6ff140ef1de0a3a9bfe4fdee64893ac1ca2036d75662228a1b3cb3641dd55450633b2a6a653e6779069cf4a31
7
+ data.tar.gz: 1d8921ad67593e9ebb48eea281eef11d4fea098b70cd0c68de70552126b91fc32f28eb018a81d0ae1ae7f5ebe0578ba54e699d40e3416d72510e9f8fe4e19436
data/.travis.yml CHANGED
@@ -1,15 +1,18 @@
1
1
  sudo: false
2
2
  language: ruby
3
- rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3.0
7
- - rbx
8
- - jruby-9
9
3
 
10
- before_install:
11
- - rvm get head
12
- - rvm reload
13
- - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
14
- install: 'bundle install --retry=3'
4
+ install: 'gem install bundler; bundle install --retry=3'
15
5
  script: 'ruby -vr bundler/setup -S rake test'
6
+
7
+ matrix:
8
+ include:
9
+ - rvm: 2.2
10
+ - rvm: 2.3
11
+ - rvm: 2.4
12
+ - rvm: ruby-head
13
+ - rvm: jruby
14
+ env: JRUBY_OPTS=--debug
15
+ - rvm: rbx
16
+
17
+ allow_failures:
18
+ - rvm: rbx
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGES
2
2
 
3
+ ## promise_pool 0.9.1 -- 2018-03-20
4
+
5
+ * Introduced PromisePool::Future.resolve to convert nested futures
6
+
3
7
  ## promise_pool 0.9.0 -- 2016-01-29
4
8
 
5
9
  * First beta!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # promise_pool [![Build Status](https://secure.travis-ci.org/godfat/promise_pool.png?branch=master)](http://travis-ci.org/godfat/promise_pool) [![Coverage Status](https://coveralls.io/repos/godfat/promise_pool/badge.png)](https://coveralls.io/r/godfat/promise_pool) [![Join the chat at https://gitter.im/godfat/promise_pool](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/promise_pool)
1
+ # promise_pool [![Build Status](https://secure.travis-ci.org/godfat/promise_pool.png?branch=master)](http://travis-ci.org/godfat/promise_pool) [![Coverage Status](https://coveralls.io/repos/github/godfat/promise_pool/badge.png)](https://coveralls.io/github/godfat/promise_pool) [![Join the chat at https://gitter.im/godfat/promise_pool](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/promise_pool)
2
2
 
3
3
  by Lin Jen-Shin ([godfat](http://godfat.org))
4
4
 
@@ -7,6 +7,7 @@ by Lin Jen-Shin ([godfat](http://godfat.org))
7
7
  * [github](https://github.com/godfat/promise_pool)
8
8
  * [rubygems](https://rubygems.org/gems/promise_pool)
9
9
  * [rdoc](http://rdoc.info/projects/godfat/promise_pool)
10
+ * [issues](https://github.com/godfat/promise_pool/issues) (feel free to ask for support)
10
11
 
11
12
  ## DESCRIPTION:
12
13
 
@@ -24,7 +25,7 @@ This was extracted from [rest-core][] because rest-core itself is getting
24
25
  too complex, and extracting promises from it could greatly reduce complexity
25
26
  and improve modularity for both rest-core and promise_pool.
26
27
 
27
- * [rest-core]: https://github.com/godfat/rest-core
28
+ [rest-core]: https://github.com/godfat/rest-core
28
29
 
29
30
  ## REQUIREMENTS:
30
31
 
@@ -122,6 +123,49 @@ Prints:
122
123
  nnf
123
124
  ```
124
125
 
126
+ ### Serialization for single future
127
+
128
+ Sometimes we would like to serialize the result from future, however although
129
+ futures are full-blown proxies, some serializers just can't serialize them.
130
+
131
+ For example, while `JSON` could dump and load them, `Marshal` can't. So it
132
+ would be great that if we could somehow uncover the future and get the result
133
+ underneath.
134
+
135
+ For single value future, we could just call `itself` or `tap{}` to do that.
136
+
137
+ ``` ruby
138
+ require 'promise_pool/promise'
139
+
140
+ future = PromisePool::Promise.new.defer{ 0 }.future
141
+ puts Marshal.load(Marshal.dump(future.itself))
142
+ ```
143
+
144
+ Prints:
145
+
146
+ ```
147
+ 0
148
+ ```
149
+
150
+ ### Serialization for nested futures
151
+
152
+ For nested futures, we could use `PromisePool::Future.resolve` to help us.
153
+
154
+ ``` ruby
155
+ require 'promise_pool/promise'
156
+
157
+ value = PromisePool::Promise.new.defer{ 0 }.future
158
+ array = PromisePool::Promise.new.defer{ [value] }.future
159
+
160
+ puts Marshal.load(Marshal.dump(PromisePool::Future.resolve(array)))
161
+ ```
162
+
163
+ Prints:
164
+
165
+ ```
166
+ [0]
167
+ ```
168
+
125
169
  ### PromisePool::ThreadPool
126
170
 
127
171
  With a thread pool, we could throttle the process and avoid exhausting
@@ -185,9 +229,9 @@ execution expired
185
229
 
186
230
  ## LICENSE:
187
231
 
188
- Apache License 2.0
232
+ Apache License 2.0 (Apache-2.0)
189
233
 
190
- Copyright (c) 2016, Lin Jen-Shin (godfat)
234
+ Copyright (c) 2016-2018, Lin Jen-Shin (godfat)
191
235
 
192
236
  Licensed under the Apache License, Version 2.0 (the "License");
193
237
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,14 +1,15 @@
1
1
 
2
2
  begin
3
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
3
+ require "#{__dir__}/task/gemgem"
4
4
  rescue LoadError
5
5
  sh 'git submodule update --init --recursive'
6
6
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
7
  end
8
8
 
9
- Gemgem.init(dir) do |s|
9
+ Gemgem.init(__dir__) do |s|
10
10
  require 'promise_pool/version'
11
11
  s.name = 'promise_pool'
12
12
  s.version = PromisePool::VERSION
13
+
13
14
  s.add_runtime_dependency('timers', '>=4.0.1')
14
15
  end
@@ -1,6 +1,21 @@
1
1
 
2
2
  module PromisePool
3
3
  class Future < BasicObject
4
+ def self.resolve future
5
+ if future.kind_of?(::Array)
6
+ future.map(&method(:resolve))
7
+
8
+ elsif future.kind_of?(::Hash)
9
+ future.inject({}) do |r, (k, v)|
10
+ r[k] = resolve(v)
11
+ r
12
+ end
13
+
14
+ else
15
+ future.itself
16
+ end
17
+ end
18
+
4
19
  def initialize promise
5
20
  @promise = promise
6
21
  end
@@ -3,5 +3,5 @@ require 'promise_pool'
3
3
  require 'pork/auto'
4
4
  require 'muack'
5
5
 
6
- Pork::Executor.include(Muack::API)
6
+ Pork::Suite.include(Muack::API)
7
7
  include PromisePool
@@ -1,4 +1,4 @@
1
1
 
2
2
  module PromisePool
3
- VERSION = '0.9.0'
3
+ VERSION = '0.9.1'
4
4
  end
data/promise_pool.gemspec CHANGED
@@ -1,61 +1,61 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: promise_pool 0.9.0 ruby lib
2
+ # stub: promise_pool 0.9.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "promise_pool"
6
- s.version = "0.9.0"
5
+ s.name = "promise_pool".freeze
6
+ s.version = "0.9.1"
7
7
 
8
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2016-01-29"
12
- s.description = "promise_pool is a promise implementation backed by threads or threads pool."
13
- s.email = ["godfat (XD) godfat.org"]
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
+ s.date = "2018-03-20"
12
+ s.description = "promise_pool is a promise implementation backed by threads or threads pool.".freeze
13
+ s.email = ["godfat (XD) godfat.org".freeze]
14
14
  s.files = [
15
- ".gitignore",
16
- ".gitmodules",
17
- ".travis.yml",
18
- "CHANGES.md",
19
- "Gemfile",
20
- "README.md",
21
- "Rakefile",
22
- "lib/promise_pool.rb",
23
- "lib/promise_pool/future.rb",
24
- "lib/promise_pool/promise.rb",
25
- "lib/promise_pool/queue.rb",
26
- "lib/promise_pool/task.rb",
27
- "lib/promise_pool/test.rb",
28
- "lib/promise_pool/thread_pool.rb",
29
- "lib/promise_pool/timer.rb",
30
- "lib/promise_pool/version.rb",
31
- "promise_pool.gemspec",
32
- "task/README.md",
33
- "task/gemgem.rb",
34
- "test/test_future.rb",
35
- "test/test_promise.rb",
36
- "test/test_readme.rb",
37
- "test/test_thread_pool.rb",
38
- "test/test_timer.rb"]
39
- s.homepage = "https://github.com/godfat/promise_pool"
40
- s.licenses = ["Apache License 2.0"]
41
- s.rubygems_version = "2.5.1"
42
- s.summary = "promise_pool is a promise implementation backed by threads or threads pool."
15
+ ".gitignore".freeze,
16
+ ".gitmodules".freeze,
17
+ ".travis.yml".freeze,
18
+ "CHANGES.md".freeze,
19
+ "Gemfile".freeze,
20
+ "README.md".freeze,
21
+ "Rakefile".freeze,
22
+ "lib/promise_pool.rb".freeze,
23
+ "lib/promise_pool/future.rb".freeze,
24
+ "lib/promise_pool/promise.rb".freeze,
25
+ "lib/promise_pool/queue.rb".freeze,
26
+ "lib/promise_pool/task.rb".freeze,
27
+ "lib/promise_pool/test.rb".freeze,
28
+ "lib/promise_pool/thread_pool.rb".freeze,
29
+ "lib/promise_pool/timer.rb".freeze,
30
+ "lib/promise_pool/version.rb".freeze,
31
+ "promise_pool.gemspec".freeze,
32
+ "task/README.md".freeze,
33
+ "task/gemgem.rb".freeze,
34
+ "test/test_future.rb".freeze,
35
+ "test/test_promise.rb".freeze,
36
+ "test/test_readme.rb".freeze,
37
+ "test/test_thread_pool.rb".freeze,
38
+ "test/test_timer.rb".freeze]
39
+ s.homepage = "https://github.com/godfat/promise_pool".freeze
40
+ s.licenses = ["Apache-2.0".freeze]
41
+ s.rubygems_version = "2.7.6".freeze
42
+ s.summary = "promise_pool is a promise implementation backed by threads or threads pool.".freeze
43
43
  s.test_files = [
44
- "test/test_future.rb",
45
- "test/test_promise.rb",
46
- "test/test_readme.rb",
47
- "test/test_thread_pool.rb",
48
- "test/test_timer.rb"]
44
+ "test/test_future.rb".freeze,
45
+ "test/test_promise.rb".freeze,
46
+ "test/test_readme.rb".freeze,
47
+ "test/test_thread_pool.rb".freeze,
48
+ "test/test_timer.rb".freeze]
49
49
 
50
50
  if s.respond_to? :specification_version then
51
51
  s.specification_version = 4
52
52
 
53
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<timers>, [">= 4.0.1"])
54
+ s.add_runtime_dependency(%q<timers>.freeze, [">= 4.0.1"])
55
55
  else
56
- s.add_dependency(%q<timers>, [">= 4.0.1"])
56
+ s.add_dependency(%q<timers>.freeze, [">= 4.0.1"])
57
57
  end
58
58
  else
59
- s.add_dependency(%q<timers>, [">= 4.0.1"])
59
+ s.add_dependency(%q<timers>.freeze, [">= 4.0.1"])
60
60
  end
61
61
  end
data/task/README.md CHANGED
@@ -4,16 +4,16 @@
4
4
 
5
5
  Provided tasks:
6
6
 
7
- rake clean # Remove ignored files
7
+ rake clean # Trash ignored files
8
8
  rake gem:build # Build gem
9
9
  rake gem:install # Install gem
10
10
  rake gem:release # Release gem
11
11
  rake gem:spec # Generate gemspec
12
- rake test # Run tests in memory
12
+ rake test # Run tests
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
16
- * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
16
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
17
17
 
18
18
  ## INSTALLATION:
19
19
 
@@ -23,13 +23,13 @@ And in Rakefile:
23
23
 
24
24
  ``` ruby
25
25
  begin
26
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
26
+ require "#{__dir__}/task/gemgem"
27
27
  rescue LoadError
28
- sh 'git submodule update --init'
28
+ sh 'git submodule update --init --recursive'
29
29
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
30
  end
31
31
 
32
- Gemgem.init(dir) do |s|
32
+ Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
33
33
  s.name = 'your-gem'
34
34
  s.version = '0.1.0'
35
35
  end
@@ -37,9 +37,9 @@ end
37
37
 
38
38
  ## LICENSE:
39
39
 
40
- Apache License 2.0
40
+ Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
43
43
 
44
44
  Licensed under the Apache License, Version 2.0 (the "License");
45
45
  you may not use this file except in compliance with the License.
data/task/gemgem.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Gemgem
3
3
  class << self
4
- attr_accessor :dir, :spec, :spec_create
4
+ attr_accessor :dir, :spec, :submodules, :spec_create
5
5
  end
6
6
 
7
7
  module_function
@@ -11,12 +11,14 @@ module Gemgem
11
11
  def pkg_dir ; "#{dir}/pkg" ; end
12
12
  def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
13
 
14
- def init dir, &block
14
+ def init dir, options={}, &block
15
15
  self.dir = dir
16
- $LOAD_PATH.unshift("#{dir}/lib")
17
16
  ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
17
  ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
18
+ self.submodules = options[:submodules] || []
19
19
  self.spec_create = block
20
+
21
+ $LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
20
22
  end
21
23
 
22
24
  def create
@@ -26,7 +28,7 @@ module Gemgem
26
28
 
27
29
  s.description = description.join
28
30
  s.summary = description.first
29
- s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
31
+ s.license = license
30
32
 
31
33
  s.date = Time.now.strftime('%Y-%m-%d')
32
34
  s.files = gem_files
@@ -115,6 +117,7 @@ module Gemgem
115
117
  SimpleCov.start do
116
118
  add_filter('test/')
117
119
  add_filter('test.rb')
120
+ submodules_libs.each(&method(:add_filter))
118
121
  end
119
122
  end
120
123
 
@@ -159,11 +162,15 @@ module Gemgem
159
162
  end
160
163
 
161
164
  def strip_home_path path
162
- path.sub(ENV['HOME'], '~')
165
+ path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
163
166
  end
164
167
 
165
168
  def strip_cwd_path path
166
- path.sub(Dir.pwd, '.')
169
+ path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
170
+ end
171
+
172
+ def submodules_libs
173
+ submodules.map{ |path| "#{dir}/#{path}/lib" }
167
174
  end
168
175
 
169
176
  def git *args
@@ -201,6 +208,11 @@ module Gemgem
201
208
  @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
202
209
  end
203
210
 
211
+ def license
212
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
213
+ split(/[()]/).map(&:strip).reject(&:empty?).last
214
+ end
215
+
204
216
  def all_files
205
217
  @all_files ||= fold_files(glob).sort
206
218
  end
@@ -221,7 +233,8 @@ module Gemgem
221
233
 
222
234
  def gem_files
223
235
  @gem_files ||= all_files.reject{ |f|
224
- f =~ ignored_pattern && !git_files.include?(f)
236
+ f =~ submodules_pattern ||
237
+ (f =~ ignored_pattern && !git_files.include?(f))
225
238
  }
226
239
  end
227
240
 
@@ -253,6 +266,15 @@ module Gemgem
253
266
  end
254
267
  end
255
268
 
269
+ def submodules_pattern
270
+ @submodules_pattern ||= if submodules.empty?
271
+ /^$/
272
+ else
273
+ Regexp.new(submodules.map{ |path|
274
+ "^#{Regexp.escape(path)}/" }.join('|'))
275
+ end
276
+ end
277
+
256
278
  def expand_patterns pathes
257
279
  # http://git-scm.com/docs/gitignore
258
280
  pathes.flat_map{ |path|
data/test/test_future.rb CHANGED
@@ -23,4 +23,12 @@ describe PromisePool::Future do
23
23
  would 'respond_to_missing? properly' do
24
24
  [Promise.new.defer{0}.future].flatten.first.should.eq 0
25
25
  end
26
+
27
+ would 'resolve deep futures so that it could be serialized' do
28
+ value = Promise.new.defer{ 0 }.future
29
+ array = Promise.new.defer{ [value] }.future
30
+ hash = Promise.new.defer{ {:a => array} }.future
31
+
32
+ expect(Marshal.load(Marshal.dump(Future.resolve(hash)))).eq(:a => [0])
33
+ end
26
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promise_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timers
@@ -58,7 +58,7 @@ files:
58
58
  - test/test_timer.rb
59
59
  homepage: https://github.com/godfat/promise_pool
60
60
  licenses:
61
- - Apache License 2.0
61
+ - Apache-2.0
62
62
  metadata: {}
63
63
  post_install_message:
64
64
  rdoc_options: []
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.5.1
79
+ rubygems_version: 2.7.6
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: promise_pool is a promise implementation backed by threads or threads pool.