hustle 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 462fcf478bc5d9197719e9ef8bba3fe84b37feb0
4
- data.tar.gz: f3fc2d990f6785078a950ba50db9ee054d1f2f3e
3
+ metadata.gz: 0751e2a30bd9eaa27e1a2d91386ac2e708e3dec2
4
+ data.tar.gz: b398cd8b489a16bfeb07ad6ecae646dac4633d6d
5
5
  SHA512:
6
- metadata.gz: 1622258db577a0920d424f748f8a69db14dcf25be289a49c788822badb6afa878913b131f8a66dec1efaeba7e7fd2d8caee9b366fe92b8780de7f366359223ad
7
- data.tar.gz: caf7fc6a675195d560c795847ef2a1c59ac2a406dcf082156ffe6fb4d655026ee44ba7bb06be5e40a77b24130ad2a7814502b1640163a6cc030c3fbda1ee9277
6
+ metadata.gz: 49e168a14e448afe2a261672f0493588219bd86fbb0055374a730fa52bc7d22f33f6479598f0ef7d8516ff75506ebd69a7435fdbad26a86527a7a979dc88fd40
7
+ data.tar.gz: 046f513b6dd4045aa34091c854f9fd9e1b88ee099689b3787f6ecdc32d64e10c372a749a8d533610eb69a0ceae6d03d08d103fc7167fca8a06c066d08a1d8201
data/lib/hustle/runner.rb CHANGED
@@ -41,17 +41,10 @@ module Hustle
41
41
  end
42
42
 
43
43
  def run_remote(&block)
44
+ sleep 0 while !remote_instance_ready?
44
45
  remote_instance.run(&block)
45
46
  end
46
47
 
47
- def remote_instance_finished?
48
- remote_instance.finished?
49
- end
50
-
51
- def remote_value
52
- remote_instance.value
53
- end
54
-
55
48
  # methods to be run on the remote instance
56
49
 
57
50
  def stop
@@ -59,20 +52,13 @@ module Hustle
59
52
  end
60
53
 
61
54
  def run
62
- Thread.new do
63
- begin
64
- @value = yield
65
- rescue Exception => e
66
- @value = e
67
- end
68
- @finished = true
55
+ begin
56
+ yield
57
+ rescue Exception => e
58
+ e
69
59
  end
70
60
  end
71
61
 
72
- def finished?
73
- !!@finished
74
- end
75
-
76
62
  end
77
63
 
78
64
  end
@@ -1,3 +1,3 @@
1
1
  module Hustle
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/hustle.rb CHANGED
@@ -27,7 +27,10 @@ module Hustle
27
27
  end
28
28
 
29
29
  def start_drb
30
- @drb ||= DRb.start_service
30
+ @drb ||= begin
31
+ DRb.start_service
32
+ sleep 0 while server.is_a?(DRb::DRbServerNotFound)
33
+ end
31
34
  end
32
35
 
33
36
  def stop_drb
@@ -45,12 +48,10 @@ module Hustle
45
48
  uri = "druby://127.0.0.1:#{random_port}"
46
49
  runner = Runner.new(uri)
47
50
  runner.start_remote_instance
48
- sleep 0 while !runner.remote_instance_ready?
49
51
  synchronize do
50
52
  active_runners[runner.pid] = runner
51
53
  end
52
- runner.run_remote(&block)
53
- finish runner, callback
54
+ finish runner, callback, &block
54
55
  end
55
56
 
56
57
  def wait
@@ -69,19 +70,26 @@ module Hustle
69
70
  port
70
71
  end
71
72
 
72
- def finish(runner, callback)
73
+ def finish(runner, callback, &block)
73
74
  runner.callback_thread = Thread.new do
74
- sleep 0.01 while !runner.remote_instance_finished?
75
- value = runner.remote_value
75
+ value = runner.run_remote(&block)
76
76
  runner.stop_remote_instance
77
- stop_drb
78
77
  synchronize do
79
78
  active_runners.delete(runner.pid)
80
79
  end
80
+ stop_drb
81
81
  callback.call value
82
82
  end
83
83
  end
84
84
 
85
+ def server
86
+ begin
87
+ DRb.current_server
88
+ rescue DRb::DRbServerNotFound => e
89
+ e
90
+ end
91
+ end
92
+
85
93
  end
86
94
 
87
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hustle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins