hustle 0.0.4 → 0.0.5

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: c8fb122e01f5a7a7434a81d4407794b313cd36a4
4
- data.tar.gz: f90f07d87d1b73ccdd480a0de9be5fbab9c4db2b
3
+ metadata.gz: 8bede7b90ce5b7f0ce331158167b2dcf894681a8
4
+ data.tar.gz: dd74a082c67416a7b99708ec72d51b50310489b0
5
5
  SHA512:
6
- metadata.gz: f393b3dfc7c25a44434bc342a33d56a6434d70a7e806083de142eaeaa1c5bb79ad4b56f4e65136e49d2e151a11db05d127dc1e275657c6a547c3744d3fda14a3
7
- data.tar.gz: f48ebf55c0f69ad9f64917ebfe8ddea5e3446647ac2e7e89e9dd442760e51bab96b179d3ac8522195428bcc00b77a43b41bc2d5dce028412b9c88d9e205ad4f9
6
+ metadata.gz: 80e458ab378dbad7fac515e6c9205699c9029ed5f146f6eaa56897763ec98343aa3e16cf01bf783a0eeafc2920101c9211a4d1aba0fee0755b0fb91e8ea0735b
7
+ data.tar.gz: 4cbca72cfb4a34733f2dd19bb80773031714d9b82ec23dddce2677bc9a9a3e69a5b707c2bb95f4d2d41b3a3938d22b1d5b1b1a7ec88e88bbfb0c3f0edd265d7e
data/lib/hustle/runner.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "sourcify"
2
+
1
3
  module Hustle
2
4
  class Runner
3
5
  attr_reader :uri, :pid, :value
@@ -41,7 +43,8 @@ module Hustle
41
43
 
42
44
  def run_remote(&block)
43
45
  sleep 0 while !remote_instance_ready?
44
- remote_instance.run(&block)
46
+ source = block.to_source(strip_enclosure: true)
47
+ remote_instance.run source
45
48
  end
46
49
 
47
50
  # methods to be run on the remote instance
@@ -50,9 +53,9 @@ module Hustle
50
53
  DRb.stop_service
51
54
  end
52
55
 
53
- def run
56
+ def run(source)
54
57
  begin
55
- yield
58
+ eval source
56
59
  rescue Exception => e
57
60
  e
58
61
  end
@@ -1,3 +1,3 @@
1
1
  module Hustle
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/test/hustle_test.rb CHANGED
@@ -13,41 +13,45 @@ class HustleTest < MicroTest::Test
13
13
  Hustle.wait
14
14
  end
15
15
 
16
- test "mutate state in primary process" do
17
- data = { foo: nil, bar: nil }
18
-
16
+ test "callback value" do
19
17
  asserts = -> (value) do
20
- assert data[:foo] == 1
21
- assert data[:bar] == 2
18
+ assert Process.pid != value
22
19
  end
23
20
 
24
- Hustle.go callback: asserts do
25
- data[:foo] = 1
26
- data[:bar] = 2
21
+ Hustle.go(callback: asserts) do
22
+ Process.pid
27
23
  end
24
+
25
+ Hustle.wait
28
26
  end
29
27
 
30
- test "callback value" do
28
+ test "error in block" do
31
29
  asserts = -> (value) do
32
- assert Process.pid != value
30
+ assert value.is_a?(ZeroDivisionError)
33
31
  end
34
32
 
35
33
  Hustle.go(callback: asserts) do
36
- Process.pid
34
+ 1/0
37
35
  end
38
- end
39
36
 
40
- test "error in block" do
41
- error_message = "Error in the block!"
37
+ Hustle.wait
38
+ end
42
39
 
40
+ test "cpu intense work" do
43
41
  asserts = -> (value) do
44
- assert value.is_a?(StandardError)
45
- assert value.message == error_message
42
+ assert value == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817]
46
43
  end
47
44
 
48
- Hustle.go(callback: asserts) do
49
- raise error_message
45
+ Hustle.go callback: asserts do
46
+ class Fibinocci
47
+ def calc(n)
48
+ n < 2 ? n : calc(n-1) + calc(n-2)
49
+ end
50
+ end
51
+ 38.times.map { |i| Fibinocci.new.calc(i) }
50
52
  end
53
+
54
+ Hustle.wait
51
55
  end
52
56
 
53
57
  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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: ParseTree
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: sourcify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.0
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement