asynchronize 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/lib/asynchronize.rb +9 -12
- data/readme.md +14 -8
- data/spec/minitest_helper.rb +0 -2
- data/spec/spec.rb +0 -7
- metadata +3 -4
- data/Rakefile +0 -8
- data/asynchronize.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f84e1c57b42abe8917434680f2a3889a4edc2608af231513f3b24bbe77d2e2c
|
4
|
+
data.tar.gz: 8dabfe07d60a388bf73a2b7c2c3b36a8d941bf0f8502bd425b4736c2ec81fc2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23744ccb079b4e39828a9d11a46be4a56e97869f88a9e99661685fc405fa609ed92a046ce22b3642670028ccf951c5558246269418967826741184cfbf43c206
|
7
|
+
data.tar.gz: 2442aaf5bcc17538b569c00fd28b76fdfb9451d25160b47b1763e7237238d22309c49acac4c141745226e4a07f665e0feb691748d0303ea480dd75a7e06d6052
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Kenneth Cochran
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/lib/asynchronize.rb
CHANGED
@@ -23,11 +23,10 @@ module Asynchronize
|
|
23
23
|
# @example To add any number of methods to be asynchronized.
|
24
24
|
# asynchronize :method1, :method2, :methodn
|
25
25
|
def self.asynchronize(*methods)
|
26
|
-
@methods_to_async.merge(methods)
|
26
|
+
@methods_to_async.merge(methods.map {|m| m.hash})
|
27
27
|
methods.each do |method|
|
28
28
|
# If it's not defined yet, we'll get it with method_added
|
29
|
-
|
30
|
-
Asynchronize.create_new_method(method, self)
|
29
|
+
Asynchronize.create_new_method(method, self) if method_defined?(method)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -47,10 +46,10 @@ module Asynchronize
|
|
47
46
|
# Return if this is an inherited class that hasn't included asynchronize
|
48
47
|
return if @methods_asyncing.nil?
|
49
48
|
# Return if we're already processing this method
|
50
|
-
return if @methods_asyncing.include?(method)
|
51
|
-
@methods_asyncing.add(method)
|
49
|
+
return if @methods_asyncing.include?(method.hash)
|
50
|
+
@methods_asyncing.add(method.hash)
|
52
51
|
self.old_method_added(method) if self.methods.include?(:old_method_added)
|
53
|
-
return unless @methods_to_async.include?(method)
|
52
|
+
return unless @methods_to_async.include?(method.hash)
|
54
53
|
# This will delete from @methods_asyncing
|
55
54
|
Asynchronize.create_new_method(method, self)
|
56
55
|
end
|
@@ -62,15 +61,13 @@ module Asynchronize
|
|
62
61
|
def self.create_new_method(method, klass)
|
63
62
|
klass.instance_eval do
|
64
63
|
old_method = instance_method(method)
|
65
|
-
|
66
|
-
# was redefined.
|
67
|
-
return if @asynced_methods.include?(old_method)
|
64
|
+
return if @asynced_methods.include?(old_method.hash)
|
68
65
|
undef_method(method)
|
69
66
|
|
70
|
-
@methods_asyncing.add(method)
|
67
|
+
@methods_asyncing.add(method.hash)
|
71
68
|
define_method(method, Asynchronize._build_new_method(old_method))
|
72
|
-
@methods_asyncing.delete(method)
|
73
|
-
@asynced_methods.add(instance_method(method))
|
69
|
+
@methods_asyncing.delete(method.hash)
|
70
|
+
@asynced_methods.add(instance_method(method).hash)
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
data/readme.md
CHANGED
@@ -58,7 +58,7 @@ problems I didn't have. Now, just call asynchronize to make any method
|
|
58
58
|
asynchronous.
|
59
59
|
|
60
60
|
## Versioning Policy
|
61
|
-
Once I feel like this is ready for production code
|
61
|
+
Once I feel like this is ready for production code, version 1.0.0, this project
|
62
62
|
will follow [Semantic Versioning](https://semver.org) until then, the patch
|
63
63
|
number (0.0.x) will be updated for any changes that do not affect the public
|
64
64
|
interface. Versions that increment the minor number will have at least one of
|
@@ -88,21 +88,27 @@ We check for and alias your old method_added. It will be called before
|
|
88
88
|
anything else. Of course, if you define method_added after including
|
89
89
|
Asynchronize, you have to do the same and be careful to not overwrite ours!
|
90
90
|
|
91
|
-
### Why do I need another
|
91
|
+
### Why do I need another gem? My code's bloated enough as it is?
|
92
92
|
It's super tiny. Just a light wrapper around the existing language features.
|
93
93
|
Seriously, it's just around fifty lines of code. Actually, according to
|
94
|
-
[cloc](https://www.npmjs.com/package/cloc) there's
|
95
|
-
tests as the source. You should read it, I'd love feedback!
|
94
|
+
[cloc](https://www.npmjs.com/package/cloc) there's almost four times as many
|
95
|
+
lines in the tests as the source. You should read it, I'd love feedback!
|
96
96
|
|
97
97
|
### Do you accept contributions?
|
98
98
|
Absolutely! If your use case isn't compatible with the project, you find a
|
99
99
|
bug, or just want to donate some tests; make an issue or send a PR please.
|
100
100
|
To run the test suite, just run `bundle` then `rake` from the project directory.
|
101
101
|
|
102
|
-
### What's the difference between
|
103
|
-
|
104
|
-
|
105
|
-
regular
|
102
|
+
### What's the difference between asynchronize and promises/async..await?
|
103
|
+
Those projects and similar ones aim to create an entirely new abstraction to use
|
104
|
+
for doing things asynchronously. This project simply aims to make the existing
|
105
|
+
language features easier to use with less typing. Just define a regular method,
|
106
|
+
then interact with it's result like a regular thread.
|
107
|
+
|
108
|
+
### What versions are supported?
|
109
|
+
In theory, this should work for all versions of Ruby. So far, Travis only tests
|
110
|
+
for MRI 2.2.2 and 2.5.1. I plan on verifying and adding older versions and other
|
111
|
+
implementations as I am able.
|
106
112
|
|
107
113
|
## License
|
108
114
|
MIT
|
data/spec/minitest_helper.rb
CHANGED
data/spec/spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asynchronize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Cochran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Take any synchronous method, and run it asynchronously, without cluttering
|
14
14
|
your code with repetetive boilerplate.
|
@@ -17,8 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
-
|
21
|
-
- asynchronize.gemspec
|
20
|
+
- LICENSE
|
22
21
|
- lib/asynchronize.rb
|
23
22
|
- readme.md
|
24
23
|
- spec/minitest_helper.rb
|
data/Rakefile
DELETED
data/asynchronize.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = 'asynchronize'
|
5
|
-
s.version = '0.2.0'
|
6
|
-
s.date = Date.today.to_s
|
7
|
-
s.summary = 'Easily make multiple methods asynchronous with one line of code.'
|
8
|
-
s.description = 'Take any synchronous method, and run it asynchronously, ' +
|
9
|
-
'without cluttering your code with repetetive boilerplate.'
|
10
|
-
s.author = 'Kenneth Cochran'
|
11
|
-
s.email = 'kenneth.cochran101@gmail.com'
|
12
|
-
s.files = [
|
13
|
-
'lib/asynchronize.rb',
|
14
|
-
'spec/spec.rb',
|
15
|
-
'spec/minitest_helper.rb',
|
16
|
-
'asynchronize.gemspec',
|
17
|
-
'Rakefile',
|
18
|
-
'readme.md',
|
19
|
-
]
|
20
|
-
s.test_files = [
|
21
|
-
'spec/spec.rb',
|
22
|
-
'spec/minitest_helper.rb'
|
23
|
-
]
|
24
|
-
s.homepage = 'https://github.com/kennycoc/asynchronize'
|
25
|
-
s.license = 'MIT'
|
26
|
-
end
|