codefly 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +41 -13
- data/codefly.gemspec +1 -1
- data/lib/codefly/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c570cc226d705a39be495be7555ea1882fe36b64
|
4
|
+
data.tar.gz: e4b747f462ace7008fe64603b8f8d692faa3d339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 825671fa3341dbcb592ea57fe2db1950fa5a08b767a2c71c0cb855c60290c579aeb9c1cee24f1d3db26f330c1502def20bd342a0add639dc1e25aa0865e7cb3a
|
7
|
+
data.tar.gz: 1d8f7f4a8b21f4ffa8e67d2069e368092b67f01476c8c3c0600e991153f828ae7486598eb7f8c4d8c7fa4595746cd87ad166aa801fce4630b8c97b599c26589f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,51 @@
|
|
1
|
-
CodeFly
|
1
|
+
With CodeFly you can execute parallel / asynchronous code in Rails, in a easy way.
|
2
2
|
|
3
|
-
This is how a classic code looks like:
|
3
|
+
## This is how a classic code looks like:
|
4
4
|
```ruby
|
5
|
-
blue_cars = Vehicle.where(type: "car", color: "blue") # 1 sec
|
6
|
-
accessories = Accessory.where(type: "car") # 1 sec
|
7
|
-
|
5
|
+
@blue_cars = Vehicle.where(type: "car", color: "blue") # 0.1 sec
|
6
|
+
@accessories = Accessory.where(type: "car") # 0.1 sec
|
7
|
+
# some code
|
8
|
+
# some code using @blue_cars and @accessories
|
8
9
|
```
|
9
10
|
|
10
|
-
This is how a flied code looks like:
|
11
|
+
## This is how a flied code looks like:
|
11
12
|
```ruby
|
12
|
-
fly(:A) { blue_cars = Vehicle.where(type: "car", color: "blue") } # 1 sec
|
13
|
-
fly(:B) { accessories = Accessory.where(type: "car") } # 1 sec
|
13
|
+
fly(:A) { @blue_cars = Vehicle.where(type: "car", color: "blue") } # 0.1 sec
|
14
|
+
fly(:B) { @accessories = Accessory.where(type: "car") } # 0.1 sec
|
15
|
+
# some code
|
14
16
|
wait_fly(:A, :B)
|
15
|
-
|
17
|
+
# some code using @blue_cars and @accessories
|
16
18
|
```
|
17
19
|
|
18
|
-
The first code will take 2
|
20
|
+
The first code will take 0.2 sec, but the second will take only 0.1 sec, the twice of speed. On the second code, the A and B queries will be executed at the same time (I will assume that your DB have more than 1 core), and the Ruby will be freed to execute another code while these 2 queries are being processed.
|
19
21
|
|
20
|
-
The CodeFly methods are:
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
## The CodeFly methods are:
|
24
|
+
|
25
|
+
- *fly(id)* { async code }
|
26
|
+
- *wait_fly(id_1[, id_2, …])*: block until the async codes terminate
|
27
|
+
|
28
|
+
|
29
|
+
## Advanced techniques
|
30
|
+
|
31
|
+
You can use CodeFly to make prediction algorithms:
|
32
|
+
```ruby
|
33
|
+
fly(:ans_a) { @blue_cars = Vehicle.where(type: "car", color: "blue") }
|
34
|
+
fly(:ans_b) { @yellow_cars = Vehicle.where(type: "car", color: "yellow") }
|
35
|
+
fly(:ans_c) { @other_cars = Vehicle.where(type: "car") }
|
36
|
+
|
37
|
+
wait_fly(:ans_a)
|
38
|
+
if @blue_cars.present?
|
39
|
+
# ...
|
40
|
+
else
|
41
|
+
wait_fly(:ans_b)
|
42
|
+
if @yellow_cars.present?
|
43
|
+
#...
|
44
|
+
else
|
45
|
+
wait_fly(:ans_c)
|
46
|
+
#...
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
In this sample, you are triggering the all queries before you know what you need. So at the time that we get the first answer, the db probally provide us the others answers, saving time.
|
data/codefly.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Daniel Loureiro"]
|
10
10
|
spec.email = ["loureirorg@gmail.com"]
|
11
11
|
spec.summary = %q{Parallel / async code in Rails}
|
12
|
-
spec.description = %q{
|
12
|
+
spec.description = %q{Execute parallel / asynchronous code in Rails, in a easy way}
|
13
13
|
spec.homepage = "https://github.com/loureirorg/codefly"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/codefly/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codefly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Loureiro
|
@@ -38,8 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
42
|
-
in Rails, in a easy way.
|
41
|
+
description: Execute parallel / asynchronous code in Rails, in a easy way
|
43
42
|
email:
|
44
43
|
- loureirorg@gmail.com
|
45
44
|
executables: []
|
@@ -51,6 +50,7 @@ files:
|
|
51
50
|
- LICENSE.txt
|
52
51
|
- README.md
|
53
52
|
- Rakefile
|
53
|
+
- codefly-0.0.1.gem
|
54
54
|
- codefly.gemspec
|
55
55
|
- lib/codefly.rb
|
56
56
|
- lib/codefly/version.rb
|