asynchronize 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/asynchronize.gemspec +2 -2
- data/lib/asynchronize.rb +21 -13
- data/readme.md +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b87faff7002bd120d62dfdb0492443ea9ff339298116a65f4b648d3e69698ba
|
4
|
+
data.tar.gz: 4f278555322d36220fdf8e32ef750e550946c553009f43e9c4273005b594219f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d49afc4158a3d06e42428b008790cee9303f739bac56c8cd6dacecae57963204439e0f7d3631dc090bd5a77bde8c3985bcdf9bb13871aaf911dc9819dcdcaf
|
7
|
+
data.tar.gz: 60028e43fb1f7ca8a7fa9055750d777dfd91da8f1ae327306cc73927ab1db35632f8aacaec4cd43a80a146c77f97d740c1f7b76368de0ec3389b84a500b5b437
|
data/asynchronize.gemspec
CHANGED
@@ -2,9 +2,9 @@ require 'date'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'asynchronize'
|
5
|
-
s.version = '0.1.
|
5
|
+
s.version = '0.1.1'
|
6
6
|
s.date = Date.today.to_s
|
7
|
-
s.summary = 'Easily make multiple methods asynchronous
|
7
|
+
s.summary = 'Easily make multiple methods asynchronous with one line of code.'
|
8
8
|
s.description = 'Take any synchronous method, and run it asynchronously, ' +
|
9
9
|
'without cluttering your code with repetetive boilerplate.'
|
10
10
|
s.author = 'Kenneth Cochran'
|
data/lib/asynchronize.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Asynchronize
|
2
2
|
require 'set'
|
3
|
-
def self.included
|
3
|
+
def self.included(base)
|
4
4
|
base.class_eval do
|
5
5
|
# The methods we have already asynchronized
|
6
6
|
@@asynced_methods = Set.new
|
@@ -27,9 +27,10 @@ module Asynchronize
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.method_added(method)
|
30
|
+
# Don't do anything else if we're not actually adding a new method
|
31
|
+
return if @@methods_asyncing.include? method
|
30
32
|
old_method_added(method) if method_defined? :old_method_added
|
31
33
|
return unless @@methods_to_async.include? method
|
32
|
-
return if @@methods_asyncing.include? method
|
33
34
|
Asynchronize.create_new_method(method, self)
|
34
35
|
end
|
35
36
|
end
|
@@ -38,22 +39,29 @@ module Asynchronize
|
|
38
39
|
def self.create_new_method(method, klass)
|
39
40
|
klass.instance_eval do
|
40
41
|
old_method = instance_method(method)
|
42
|
+
# Can't just store the method name, since it would break if the method
|
43
|
+
# was redefined.
|
41
44
|
return if @@asynced_methods.include?(old_method)
|
42
45
|
undef_method method
|
43
|
-
@@methods_asyncing.add(method)
|
44
46
|
|
47
|
+
@@methods_asyncing.add(method)
|
45
48
|
define_method(method) do |*args, &block|
|
46
|
-
return
|
47
|
-
|
48
|
-
unless tblock.nil?
|
49
|
-
tblock.call(result);
|
50
|
-
else
|
51
|
-
Thread.current[:return_value] = result
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end # define_method
|
49
|
+
return _build_thread(old_method, args, block)
|
50
|
+
end
|
55
51
|
@@methods_asyncing.delete(method)
|
56
|
-
@@asynced_methods.add(instance_method
|
52
|
+
@@asynced_methods.add(instance_method(method))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def _build_thread(old_method, args, block)
|
58
|
+
return Thread.new(old_method, args, block) do |told_method, targs, tblock|
|
59
|
+
result = told_method.bind(self).call(*targs)
|
60
|
+
if tblock.nil?
|
61
|
+
Thread.current[:return_value] = result
|
62
|
+
else
|
63
|
+
tblock.call(result)
|
64
|
+
end
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
data/readme.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
[](https://travis-ci.org/kennycoc/asynchronize)
|
1
2
|
# Asynchronize
|
2
|
-
### The easiest way to make
|
3
|
+
### The easiest way to make multiple methods asynchronous.
|
3
4
|
|
4
5
|
Find yourself writing the same boilerplate for all your asynchronous methods?
|
5
6
|
Get dryyy with asynchronize.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asynchronize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Cochran
|
@@ -45,6 +45,6 @@ rubyforge_project:
|
|
45
45
|
rubygems_version: 2.7.6
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
|
-
summary: Easily make multiple methods asynchronous
|
48
|
+
summary: Easily make multiple methods asynchronous with one line of code.
|
49
49
|
test_files:
|
50
50
|
- spec/spec.rb
|