async_play 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31b3c06aa2dcad450876e83bd3dcb09601568baa
4
+ data.tar.gz: f061686add371487ac8677dc469eff1836664f65
5
+ SHA512:
6
+ metadata.gz: f7af8c96be628fafa298273a61e9d9408b73f2a8853eb3e1c244b652faa6ac84a30d20b2195baba3d10ce821be092ab5a34a26a8fb65b5817060c3b5e8291666
7
+ data.tar.gz: 98de14677fd84eb93bb90eeddd27fdb53e00278b8dfdfab8bc9f63fcfe3ca3c40c10f194b621d19d309a528c7645fe5661058cc8e313087b2363358f1398ca7c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in async_play.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # AsyncPlay
2
+
3
+ Wait for completion of the asynchronous procedure to obtain thats results.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'async_play'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install async_play
20
+
21
+ ## Usage
22
+
23
+ To obtain results from asynchronous procedure, the procedure is passed as a block to AsyncPlay#opening.
24
+ The block will be given one argiment that is a Proc to return resuts.
25
+ The end of block call the proc with results then return it from AsyncPlay#opening.
26
+
27
+
28
+ ```ruby
29
+ results = AsyncPlay.opening{ | curtain | Thread.new { curtain.call 1 } }
30
+ ```
31
+
32
+ If you do not call the proc within 1 second, AsyncPlay#opening raise an error.
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ledsun/async_play.
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
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "async_play/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "async_play"
8
+ spec.version = AsyncPlay::VERSION
9
+ spec.authors = ["ledsun"]
10
+ spec.email = ["shigeru.nakajima@gmail.com"]
11
+
12
+ spec.summary = "Wait for completion of the asynchronous procedure to obtain thats results."
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/ledsun/async_play"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "async_play"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/async_play.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "async_play/version"
2
+
3
+ module AsyncPlay
4
+ def self.opening
5
+ q = QueueWithTimeout.new
6
+
7
+ yield ->(result) { q.push result }
8
+
9
+ q.pop
10
+ end
11
+
12
+ # It is an queue occurs error if there is no result within 1 second.
13
+ # When results of asynchronous function can not be obtained,
14
+ # make an error to prevent waiting indefinitely.
15
+ # See https://spin.atomicobject.com/2014/07/07/ruby-queue-pop-timeout/
16
+ class QueueWithTimeout
17
+ def initialize
18
+ @mutex = Mutex.new
19
+ @queue = []
20
+ @recieved = ConditionVariable.new
21
+ end
22
+
23
+ def push(x)
24
+ @mutex.synchronize do
25
+ @queue << x
26
+ @recieved.signal
27
+ end
28
+ end
29
+
30
+ def pop
31
+ pop_with_timeout 1
32
+ end
33
+
34
+ private
35
+
36
+ def pop_with_timeout(timeout)
37
+ @mutex.synchronize do
38
+ if @queue.empty?
39
+ @recieved.wait(@mutex, timeout) if timeout != 0
40
+ # if we're still empty after the timeout, raise exception
41
+ raise ThreadError, "Results can not be obtained within #{timeout} second." if @queue.empty?
42
+ end
43
+ @queue.shift
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module AsyncPlay
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async_play
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ledsun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Wait for completion of the asynchronous procedure to obtain thats results.
56
+ email:
57
+ - shigeru.nakajima@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - async_play.gemspec
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/async_play.rb
72
+ - lib/async_play/version.rb
73
+ homepage: https://github.com/ledsun/async_play
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.6.12
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Wait for completion of the asynchronous procedure to obtain thats results.
96
+ test_files: []