promise.rb 0.7.2 → 0.7.3

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: d1c5730ef1d6a9d4aca9152d2d0b0978d3599bf9
4
- data.tar.gz: 7bf7f65107907530efb5befd130d8257c95b1ebd
3
+ metadata.gz: 1e3533c32b2d839c7fe076eb9ef7e02e38d594cf
4
+ data.tar.gz: 8041c55194508d424bf52709b0d55f97c75900a5
5
5
  SHA512:
6
- metadata.gz: b91773b745efae988afbcdd56080fac09398f72e781266e92b755128a3f606fc09f63299849a729c2b6e1ced9cc1cdc46581beb6880949c7ea2748516994cff3
7
- data.tar.gz: 7ca9447a4c2766299ccc9d941dd2a25d68a65a1626ff3407726966ed85157bc0c25873bf53c5eecd2a6e683c093a6217f354be5712c38602d5d02f7e7f8bb3c5
6
+ metadata.gz: b7d7ea80750476d1334d79b24c87d6b2c50a3165f336e978064eab63398722bdb5d652aac575ca9826d28305099780e40812ae9def94a23f729a657f345b09d9
7
+ data.tar.gz: c079077407ed72f4d8b0e0ba688ec623f59a23e2e3ae4240209def4c9d54bfccc19a7105e21e484dc46a6db6fa79e7be7441f45e9ba9877f74a6d8ed68c58806
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  Gemfile.lock
5
5
  pkg/
6
6
  *.rbc
7
+ *.gem
7
8
  .yardoc/
8
9
  doc/
9
10
  coverage/
@@ -1,11 +1,18 @@
1
1
  # promise.rb changelog
2
2
 
3
+ ## 0.7.3 (April 28, 2017)
4
+
5
+ ### Features
6
+
7
+ * Allow to call Promise.resolve without argument (pull #21)
8
+ * Return self from fulfill and reject (pull #22)
9
+
3
10
  ## 0.7.2 (November 15, 2016)
4
11
 
5
12
  ### Features
6
13
 
7
14
  * Add support for calling sync on the result of Promise.all (pull #24)
8
- * Add Promise.sync to unwrap an object that may be a promise. (#25)
15
+ * Add Promise.sync to unwrap an object that may be a promise. (pull #25)
9
16
 
10
17
  ## 0.7.1 (June 15, 2016)
11
18
 
data/Gemfile CHANGED
@@ -7,21 +7,21 @@ gemspec
7
7
  if Gem.ruby_version < Gem::Version.new('2.0')
8
8
  # gems that no longer support ruby 1.9.3
9
9
  gem 'json', '~> 1.8.3'
10
- gem 'tins', '~> 1.6.0'
11
10
  gem 'term-ansicolor', '~> 1.3.2'
11
+ gem 'tins', '~> 1.6.0'
12
12
  end
13
13
  if Gem.ruby_version >= Gem::Version.new('2.1')
14
- gem 'devtools', '~> 0.1.4'
14
+ gem 'devtools', '~> 0.1.16'
15
15
  end
16
- gem 'fuubar', '~> 2.0.0'
17
- gem 'awesome_print'
18
16
 
17
+ gem 'awesome_print'
18
+ gem 'coveralls', '~> 0.8.9'
19
+ gem 'fuubar', '~> 2.0.0'
19
20
  gem 'rake'
20
21
  gem 'rspec', '~> 3.5'
21
22
  gem 'rspec-its'
22
- gem 'coveralls', '~> 0.8.9'
23
23
 
24
24
  platform :rbx do
25
- gem 'rubysl', '~> 2.0'
26
25
  gem 'rubinius', '~> 2.0'
26
+ gem 'rubysl', '~> 2.0'
27
27
  end
data/README.md CHANGED
@@ -158,6 +158,15 @@ Promise.new
158
158
  .then(nil, proc { |reason| p reason })
159
159
  ```
160
160
 
161
+ In order to use the result of multiple promises, they can be grouped using
162
+ `Promise.all` for chaining.
163
+
164
+ ```ruby
165
+ sum_promise = Promise.all([promise1, promise2]).then do |value1, value2|
166
+ value1 + value2
167
+ end
168
+ ```
169
+
161
170
  ### Progress callbacks
162
171
 
163
172
  Very simple progress callbacks, as per Promises/A, are supported as well. They have been dropped in A+, but I found them to be a useful mechanism - if kept simple. Callback dispatch happens immediately in the call to `#progress`, in the order of definition via `#on_progress`. Also note that `#on_progress` does not return a new promise for chaining - the progress mechanism is meant to be very lightweight, and ignores many of the constraints and guarantees of `then`.
@@ -64,7 +64,7 @@ TooManyStatements:
64
64
  exclude:
65
65
  - initialize
66
66
  - each
67
- max_statements: 6
67
+ max_statements: 7
68
68
  UncommunicativeMethodName:
69
69
  enabled: true
70
70
  exclude: []
@@ -14,7 +14,7 @@ ParameterLists:
14
14
 
15
15
  MethodLength:
16
16
  CountComments: false
17
- Max: 10
17
+ Max: 11
18
18
 
19
19
  # Avoid more than `Max` levels of nesting.
20
20
  BlockNesting:
@@ -69,6 +69,9 @@ SignalException:
69
69
  BlockDelimiters:
70
70
  Enabled: false
71
71
 
72
+ Metrics/BlockLength:
73
+ Enabled: false
74
+
72
75
  # Allow empty lines around body
73
76
  EmptyLinesAroundBlockBody:
74
77
  Enabled: false
@@ -15,7 +15,7 @@ class Promise
15
15
  attr_accessor :source
16
16
  attr_reader :state, :value, :reason
17
17
 
18
- def self.resolve(obj)
18
+ def self.resolve(obj = nil)
19
19
  return obj if obj.is_a?(self)
20
20
  new.tap { |promise| promise.fulfill(obj) }
21
21
  end
@@ -85,7 +85,7 @@ class Promise
85
85
  @value = value
86
86
  end
87
87
  end
88
- nil
88
+ self
89
89
  end
90
90
 
91
91
  def reject(reason = nil)
@@ -94,6 +94,7 @@ class Promise
94
94
  @source = nil
95
95
  @reason = reason_coercion(reason || Error)
96
96
  end
97
+ self
97
98
  end
98
99
 
99
100
  # Override to support sync on a promise without a source or to wait
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Promise
4
- VERSION = '0.7.2'.freeze
4
+ VERSION = '0.7.3'.freeze
5
5
  end
@@ -398,12 +398,8 @@ describe Promise do
398
398
  end
399
399
 
400
400
  describe '#fulfill' do
401
- it 'does not return anything' do
402
- expect(subject.fulfill(nil)).to eq(nil)
403
- end
404
-
405
- it 'does not return anything when given a promise' do
406
- expect(subject.fulfill(Promise.new)).to eq(nil)
401
+ it 'returns itself to allow chaining' do
402
+ expect(subject.fulfill(nil)).to be(subject)
407
403
  end
408
404
 
409
405
  it 'does not require a value' do
@@ -424,8 +420,8 @@ describe Promise do
424
420
  end
425
421
 
426
422
  describe '#reject' do
427
- it 'does not return anything' do
428
- expect(subject.reject(nil)).to eq(nil)
423
+ it 'returns itself for easy chaning' do
424
+ expect(subject.reject(nil)).to be(subject)
429
425
  end
430
426
 
431
427
  it 'does not require a reason' do
@@ -558,6 +554,12 @@ describe Promise do
558
554
  expect(new_promise).to be_fulfilled
559
555
  expect(new_promise.value).to eq(42)
560
556
  end
557
+
558
+ it 'can be passed no argument' do
559
+ promise = Promise.resolve
560
+ expect(promise.fulfilled?).to eq(true)
561
+ expect(promise.value).to eq(nil)
562
+ end
561
563
  end
562
564
 
563
565
  describe '.all' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promise.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Gierth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -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.6.10
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Ruby implementation of the Promises/A+ spec