asynchronize 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: 3469c3b1731ec0b85a8014439e676153947b17adf250567a15779fc039cb39a4
4
- data.tar.gz: 7145e39f5206053ab44c1f896b3b26c242891919b48e1c4afae26ce61e2b8199
3
+ metadata.gz: 2b87faff7002bd120d62dfdb0492443ea9ff339298116a65f4b648d3e69698ba
4
+ data.tar.gz: 4f278555322d36220fdf8e32ef750e550946c553009f43e9c4273005b594219f
5
5
  SHA512:
6
- metadata.gz: f970416bd025a1e3ad544fcda9d4babb6fbf7eb75c9e764c88ed987c720f2c3122893d83aacd142ecfbbc80f1a169e6554144efef33a37d5fd96140659366dd8
7
- data.tar.gz: 3b4829c2ecccdad396c960966febf28d6176621cede70d1243aae3abd6a968c3df4a0e5fa25ff6dcd7ee0831d479c6e95bc6fec2e21a3416d48a5afa84a78ca1
6
+ metadata.gz: 73d49afc4158a3d06e42428b008790cee9303f739bac56c8cd6dacecae57963204439e0f7d3631dc090bd5a77bde8c3985bcdf9bb13871aaf911dc9819dcdcaf
7
+ data.tar.gz: 60028e43fb1f7ca8a7fa9055750d777dfd91da8f1ae327306cc73927ab1db35632f8aacaec4cd43a80a146c77f97d740c1f7b76368de0ec3389b84a500b5b437
@@ -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.0'
5
+ s.version = '0.1.1'
6
6
  s.date = Date.today.to_s
7
- s.summary = 'Easily make multiple methods asynchronous at once.'
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'
@@ -1,6 +1,6 @@
1
1
  module Asynchronize
2
2
  require 'set'
3
- def self.included base
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 Thread.new(args, block) do |targs, tblock|
47
- result = old_method.bind(self).(*targs)
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 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
+ [![Build Status](https://travis-ci.org/kennycoc/asynchronize.svg?branch=master)](https://travis-ci.org/kennycoc/asynchronize)
1
2
  # Asynchronize
2
- ### The easiest way to make a method asynchronous.
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.0
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 at once.
48
+ summary: Easily make multiple methods asynchronous with one line of code.
49
49
  test_files:
50
50
  - spec/spec.rb