apromise 0.1.0 → 0.1.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
2
  SHA256:
3
- metadata.gz: 7032a81f755992be3d24ec7a0797eabe45d5a2794f22a5bfb35dfc449c76123d
4
- data.tar.gz: 68227d14c7dc641d8d96ef7ee979e0a4f0dd0f6b3ba6f6356ab23bce30e304db
3
+ metadata.gz: b012d230ae1e0ee2352da3e53ca42588eef1e1f08e3d8573eede9cde0f59846b
4
+ data.tar.gz: 810d68ae3fb0802257ea0d78e3b9ac74c87944bcdc9c0c538882f310d093d318
5
5
  SHA512:
6
- metadata.gz: 6d950944bf02498f3c00f3b44f6fdfb5c3e677caf3c707f2a4120799edc26ddbff2e1b683ca64eb1156a1bbe4ad2fa6eccfb56f6bc9c533565556bf087fbe554
7
- data.tar.gz: 43a0d97816a14f44b24a1bd0809cad5b56e8b713a2bf3b00ae897146a62b023d29b8a3f723b42d593746d1b335631a7f1d053d28d0d520ca1fd166436b6f44a1
6
+ metadata.gz: 2bf354030c17ea33577bb3980034b5d455df0471bd8825f806437f72eccccfee0e9a383218e8fe0fef82cecbca618e632ea0024850b20670c81db6dacb834052
7
+ data.tar.gz: 7b21a151d0e887ed6d14985e6abf47edd224427f12a55742d400ceef325e2868e3011f7bdfd715d075d2f2a198639b4dd0e4963abdc1804b39475755a5160483
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apromise.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
8
+
9
+ gem 'async-rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apromise (0.1.0)
5
+ async
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ async (1.29.0)
11
+ console (~> 1.10)
12
+ nio4r (~> 2.3)
13
+ timers (~> 4.1)
14
+ async-rspec (1.16.0)
15
+ rspec (~> 3.0)
16
+ rspec-files (~> 1.0)
17
+ rspec-memory (~> 1.0)
18
+ console (1.12.0)
19
+ fiber-local
20
+ diff-lcs (1.4.4)
21
+ fiber-local (1.0.0)
22
+ nio4r (2.5.7)
23
+ rake (12.3.3)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-files (1.1.1)
34
+ rspec (~> 3.0)
35
+ rspec-memory (1.0.2)
36
+ rspec (~> 3.0)
37
+ rspec-mocks (3.10.2)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-support (3.10.2)
41
+ timers (4.3.3)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ apromise!
48
+ async-rspec
49
+ rake (~> 12.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 2.2.16
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/apromise.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'apromise'
3
+ spec.version = File.readlines(File.expand_path('VERSION', __dir__)).first.chomp
4
+ spec.authors = [ 'Scott Tadman' ]
5
+ spec.email = %w[ tadman@postageapp.com ]
6
+
7
+ spec.summary = %q{A Promise for Async}
8
+ spec.description = %q{Promise implementation for Ruby Async}
9
+ spec.homepage = 'https://github.com/postageapp/apromise'
10
+ spec.license = 'MIT'
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
12
+
13
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/postageapp/apromise'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/postageapp/apromise'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{(?:\A(?:(?:bin|test|spec|features)/|\.))|(?:\.(?:md|txt)\z)})
24
+ end
25
+ end
26
+
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = %w[ lib ]
30
+
31
+ spec.add_dependency 'async'
32
+ end
data/lib/apromise.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'async/condition'
2
+ require 'async/notification'
3
+
4
+ class APromise < Async::Condition
5
+ # == Constants ============================================================
6
+
7
+ VERSION = File.readlines(File.expand_path('../VERSION', __dir__)).first.chomp.freeze
8
+ NOT_SPECIFIED = Object.new
9
+
10
+ # == Extensions ===========================================================
11
+
12
+ # == Properties ===========================================================
13
+
14
+ # == Class Methods ========================================================
15
+
16
+ def self.version
17
+ VERSION
18
+ end
19
+
20
+ # == Instance Methods =====================================================
21
+
22
+ def initialize(value: NOT_SPECIFIED)
23
+ if (block_given?)
24
+ begin
25
+ @value = yield
26
+ rescue Exception => e
27
+ @value = e
28
+ end
29
+ elsif (value === NOT_SPECIFIED)
30
+ # Do nothing
31
+ else
32
+ @value = value
33
+ end
34
+
35
+ super()
36
+ end
37
+
38
+ def waiting?
39
+ @waiting.any?
40
+ end
41
+
42
+ def resolved?
43
+ defined?(@value)
44
+ end
45
+
46
+ def resolve(value: nil, task: nil)
47
+ @value = value
48
+
49
+ if (block_given?)
50
+ begin
51
+ @value = yield
52
+ rescue Exception => e
53
+ @value = e
54
+ end
55
+ end
56
+
57
+ reactor = (task ||= Async::Task.current).reactor
58
+
59
+ reactor << Async::Notification::Signal.new(@waiting, @value)
60
+ reactor.yield
61
+
62
+ @waiting = [ ]
63
+
64
+ nil
65
+ end
66
+
67
+ def wait
68
+ if (defined?(@value))
69
+ case (@value)
70
+ when Exception
71
+ raise @value
72
+ else
73
+ return @value
74
+ end
75
+ end
76
+
77
+ super
78
+ end
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apromise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Tadman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -30,7 +30,13 @@ email:
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
- files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - Rakefile
37
+ - VERSION
38
+ - apromise.gemspec
39
+ - lib/apromise.rb
34
40
  homepage: https://github.com/postageapp/apromise
35
41
  licenses:
36
42
  - MIT
@@ -39,7 +45,7 @@ metadata:
39
45
  homepage_uri: https://github.com/postageapp/apromise
40
46
  source_code_uri: https://github.com/postageapp/apromise
41
47
  changelog_uri: https://github.com/postageapp/apromise
42
- post_install_message:
48
+ post_install_message:
43
49
  rdoc_options: []
44
50
  require_paths:
45
51
  - lib
@@ -54,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
60
  - !ruby/object:Gem::Version
55
61
  version: '0'
56
62
  requirements: []
57
- rubygems_version: 3.1.2
58
- signing_key:
63
+ rubygems_version: 3.2.15
64
+ signing_key:
59
65
  specification_version: 4
60
66
  summary: A Promise for Async
61
67
  test_files: []