fibril 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -3
  3. data/examples/example_async.rb +7 -21
  4. data/examples/example_coop_multi_tasking.rb +33 -0
  5. data/examples/example_enum_tick.rb +9 -0
  6. data/examples/example_execution_order.rb +14 -0
  7. data/examples/example_future_async_await.rb +22 -0
  8. data/examples/example_future_sync_await.rb +23 -0
  9. data/examples/example_guard.rb +9 -7
  10. data/examples/example_guard2.rb +19 -0
  11. data/examples/example_guard3.rb +46 -0
  12. data/examples/example_http.rb +60 -0
  13. data/examples/example_multiple_loops.rb +78 -0
  14. data/examples/example_redis.rb +49 -0
  15. data/examples/{example_loop.rb → example_tick.rb} +1 -1
  16. data/examples/example_tick2.rb +22 -0
  17. data/examples/example_timeout.rb +9 -0
  18. data/fibril.gemspec +1 -1
  19. data/fibril.todo +22 -16
  20. data/lib/fibril.rb +2 -240
  21. data/lib/fibril/async_proxy.rb +28 -0
  22. data/lib/fibril/basic_object.rb +20 -0
  23. data/lib/fibril/control.rb +20 -0
  24. data/lib/fibril/core.rb +299 -0
  25. data/lib/fibril/extras.rb +8 -0
  26. data/lib/fibril/fasync_proxy.rb +36 -0
  27. data/lib/fibril/ffuture.rb +24 -0
  28. data/lib/fibril/fibril_proxy.rb +31 -0
  29. data/lib/fibril/forked_non_blocking_io_wrapper.rb +51 -0
  30. data/lib/fibril/future.rb +24 -0
  31. data/lib/fibril/guard.rb +123 -0
  32. data/lib/fibril/loop.rb +36 -6
  33. data/lib/fibril/non_blocking_io_wrapper.rb +60 -0
  34. data/lib/fibril/tick_proxy.rb +30 -0
  35. data/lib/fibril/version.rb +1 -1
  36. metadata +43 -8
  37. data/examples/example_1.rb +0 -71
  38. data/examples/example_2.rb +0 -80
  39. data/examples/example_3.rb +0 -82
  40. data/examples/example_promise.rb +0 -23
@@ -1,3 +1,3 @@
1
1
  class Fibril < Fiber
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fibril
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.10.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: redis
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: minitest
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -115,17 +129,38 @@ files:
115
129
  - Rakefile
116
130
  - bin/fibril
117
131
  - bin/setup
118
- - examples/example_1.rb
119
- - examples/example_2.rb
120
- - examples/example_3.rb
121
132
  - examples/example_async.rb
133
+ - examples/example_coop_multi_tasking.rb
134
+ - examples/example_enum_tick.rb
135
+ - examples/example_execution_order.rb
136
+ - examples/example_future_async_await.rb
137
+ - examples/example_future_sync_await.rb
122
138
  - examples/example_guard.rb
123
- - examples/example_loop.rb
124
- - examples/example_promise.rb
139
+ - examples/example_guard2.rb
140
+ - examples/example_guard3.rb
141
+ - examples/example_http.rb
142
+ - examples/example_multiple_loops.rb
143
+ - examples/example_redis.rb
144
+ - examples/example_tick.rb
145
+ - examples/example_tick2.rb
146
+ - examples/example_timeout.rb
125
147
  - fibril.gemspec
126
148
  - fibril.todo
127
149
  - lib/fibril.rb
150
+ - lib/fibril/async_proxy.rb
151
+ - lib/fibril/basic_object.rb
152
+ - lib/fibril/control.rb
153
+ - lib/fibril/core.rb
154
+ - lib/fibril/extras.rb
155
+ - lib/fibril/fasync_proxy.rb
156
+ - lib/fibril/ffuture.rb
157
+ - lib/fibril/fibril_proxy.rb
158
+ - lib/fibril/forked_non_blocking_io_wrapper.rb
159
+ - lib/fibril/future.rb
160
+ - lib/fibril/guard.rb
128
161
  - lib/fibril/loop.rb
162
+ - lib/fibril/non_blocking_io_wrapper.rb
163
+ - lib/fibril/tick_proxy.rb
129
164
  - lib/fibril/version.rb
130
165
  homepage: https://github.com/wouterken/Fibril
131
166
  licenses:
@@ -147,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
182
  version: '0'
148
183
  requirements: []
149
184
  rubyforge_project:
150
- rubygems_version: 2.4.5
185
+ rubygems_version: 2.5.1
151
186
  signing_key:
152
187
  specification_version: 4
153
188
  summary: Fibril
@@ -1,71 +0,0 @@
1
- require_relative '../lib/fibril'
2
-
3
- require 'benchmark'
4
-
5
-
6
- def get_5
7
- 5.tap{ async.sleep 0.5 }
8
- end
9
-
10
- def get_res
11
- starts = Time.now
12
- res = get_5
13
- ends = Time.now
14
- puts "Get res took #{ends - starts}"
15
- res
16
- end
17
- Benchmark.bm do |bm|
18
- # bm.report{
19
- # Fibril do
20
- # i = 0
21
- # await fibril{ i = get_5 + 20 + i }.until{ i > 260 },
22
- # fibril{ i = get_5 + 100 + i }.loop(2) do
23
- # puts "Final i is #{i}"
24
- # end
25
- # end
26
- # }
27
-
28
- # puts "Done"
29
- # sleep 2
30
- bm.report{
31
-
32
- Fibril do
33
- i = 0
34
- await(
35
- fibril{ starts = Time.now; res = get_res;i = res + 20 + i; puts "Weave 1 took #{Time.now - starts}" }.until{ i > 260 },
36
- fibril{ starts = Time.now; res = get_res;i = res + 100 + i; puts "Weave 2 took #{Time.now - starts}" }.loop(2)
37
- ) do
38
- puts "Final i is #{i}"
39
- end
40
- end
41
- }
42
- end
43
-
44
-
45
- # Fibril do
46
- # await fibril{ puts 1; tick; puts 3 },
47
- # fibril{ puts 2; tick; puts 4 } do
48
- # puts "Finished"
49
- # end
50
- # end
51
- # }
52
- # end
53
-
54
-
55
-
56
- # Thread.new do
57
- # [
58
- # Thread.new do
59
- # puts "Big very very very very long message 1"
60
- # puts "Big very very very very long message 2"
61
- # puts "Big very very very very long message 5"
62
- # puts "Big very very very very long message 6"
63
- # end,
64
- # Thread.new do
65
- # puts "Big very very very very long message 3"
66
- # puts "Big very very very very long message 4"
67
- # puts "Big very very very very long message 7"
68
- # puts "Big very very very very long message 8"
69
- # end
70
- # ].each(&:join)
71
- # end.join
@@ -1,80 +0,0 @@
1
- require_relative 'fibril'
2
- require "benchmark"
3
-
4
- Benchmark.bm do |bm|
5
- bm.report{
6
- i = 0
7
- 100.times do
8
- puts "A very long output statement : #{1}. Current thread: #{Thread.current}"
9
- puts "A very long output statement : #{2}. Current thread: #{Thread.current}"
10
- puts "A very long output statement : #{3}. Current thread: #{Thread.current}"
11
- puts "A very long output statement : #{4}. Current thread: #{Thread.current}"
12
- puts "A very long output statement : #{5}. Current thread: #{Thread.current}"
13
- puts "A very long output statement : #{6}. Current thread: #{Thread.current}"
14
- puts "A very long output statement : #{7}. Current thread: #{Thread.current}"
15
- puts "A very long output statement : #{8}. Current thread: #{Thread.current}"
16
- end
17
- }
18
- bm.report{
19
- i = 0
20
-
21
- 100.times do
22
- Fibril do
23
- Fibril do
24
- puts "A very long output statement : #{1}. Current thread: #{Thread.current}"
25
- puts "A very long output statement : #{2}. Current thread: #{Thread.current}"
26
- tick
27
- puts "A very long output statement : #{3}. Current thread: #{Thread.current}"
28
- puts "A very long output statement : #{4}. Current thread: #{Thread.current}"
29
- end
30
-
31
- Fibril do
32
- puts "A very long output statement : #{5}. Current thread: #{Thread.current}"
33
- puts "A very long output statement : #{6}. Current thread: #{Thread.current}"
34
- tick
35
- puts "A very long output statement : #{7}. Current thread: #{Thread.current}"
36
- puts "A very long output statement : #{8}. Current thread: #{Thread.current}"
37
- Fibril.stop
38
- end
39
- end
40
- end
41
- }
42
- bm.report{
43
- i = 0
44
- 100.times do
45
- Thread.new do
46
- [
47
- Thread.new do
48
- puts "A very long output statement : #{1}. Current thread: #{Thread.current}"
49
- puts "A very long output statement : #{2}. Current thread: #{Thread.current}"
50
- puts "A very long output statement : #{3}. Current thread: #{Thread.current}"
51
- puts "A very long output statement : #{4}. Current thread: #{Thread.current}"
52
- end,
53
- Thread.new do
54
- puts "A very long output statement : #{5}. Current thread: #{Thread.current}"
55
- puts "A very long output statement : #{6}. Current thread: #{Thread.current}"
56
- puts "A very long output statement : #{7}. Current thread: #{Thread.current}"
57
- puts "A very long output statement : #{8}. Current thread: #{Thread.current}"
58
- end
59
- ].each(&:join)
60
- end.join
61
- end
62
- }
63
- end
64
-
65
- # Thread.new do
66
- # [
67
- # Thread.new do
68
- # puts "Big very very very very long message 1"
69
- # puts "Big very very very very long message 2"
70
- # puts "Big very very very very long message 5"
71
- # puts "Big very very very very long message 6"
72
- # end,
73
- # Thread.new do
74
- # puts "Big very very very very long message 3"
75
- # puts "Big very very very very long message 4"
76
- # puts "Big very very very very long message 7"
77
- # puts "Big very very very very long message 8"
78
- # end
79
- # ].each(&:join)
80
- # end.join
@@ -1,82 +0,0 @@
1
- require_relative '../lib/fibril'
2
- require "benchmark"
3
-
4
- Benchmark.bm do |bm|
5
- bm.report{
6
- i = 0
7
- 1_000.times do
8
- print "\rA very long output statement : #{1}. Current thread: #{Thread.current}"
9
- print "\rA very long output statement : #{2}. Current thread: #{Thread.current}"
10
- print "\rA very long output statement : #{3}. Current thread: #{Thread.current}"
11
- print "\rA very long output statement : #{4}. Current thread: #{Thread.current}"
12
- print "\rA very long output statement : #{5}. Current thread: #{Thread.current}"
13
- print "\rA very long output statement : #{6}. Current thread: #{Thread.current}"
14
- print "\rA very long output statement : #{7}. Current thread: #{Thread.current}"
15
- print "\rA very long output statement : #{8}. Current thread: #{Thread.current}"
16
- end
17
- puts
18
- }
19
- bm.report{
20
- i = 0
21
-
22
- 1_000.times do
23
- Fibril do
24
- Fibril do
25
- print "\rA very long output statement : #{1}. Current thread: #{Thread.current}"
26
- print "\rA very long output statement : #{2}. Current thread: #{Thread.current}"
27
- tick
28
- print "\rA very long output statement : #{3}. Current thread: #{Thread.current}"
29
- print "\rA very long output statement : #{4}. Current thread: #{Thread.current}"
30
- end
31
-
32
- Fibril do
33
- print "\rA very long output statement : #{5}. Current thread: #{Thread.current}"
34
- print "\rA very long output statement : #{6}. Current thread: #{Thread.current}"
35
- tick
36
- print "\rA very long output statement : #{7}. Current thread: #{Thread.current}"
37
- print "\rA very long output statement : #{8}. Current thread: #{Thread.current}"
38
- end
39
- end
40
- end
41
- puts
42
- }
43
- bm.report{
44
- i = 0
45
- 1_000.times do
46
- Thread.new do
47
- [
48
- Thread.new do
49
- print "\rA very long output statement : #{1}. Current thread: #{Thread.current}"
50
- print "\rA very long output statement : #{2}. Current thread: #{Thread.current}"
51
- print "\rA very long output statement : #{3}. Current thread: #{Thread.current}"
52
- print "\rA very long output statement : #{4}. Current thread: #{Thread.current}"
53
- end,
54
- Thread.new do
55
- print "\rA very long output statement : #{5}. Current thread: #{Thread.current}"
56
- print "\rA very long output statement : #{6}. Current thread: #{Thread.current}"
57
- print "\rA very long output statement : #{7}. Current thread: #{Thread.current}"
58
- print "\rA very long output statement : #{8}. Current thread: #{Thread.current}"
59
- end
60
- ].each(&:join)
61
- end.join
62
- end
63
- puts
64
- }
65
- end
66
-
67
- # Thread.new do
68
- # [
69
- # Thread.new do
70
- # print "\rBig very very very very long message 1"
71
- # print "\rBig very very very very long message 2"
72
- # print "\rBig very very very very long message 5"
73
- # print "\rBig very very very very long message 6"
74
- # end,
75
- # Thread.new do
76
- # print "\rBig very very very very long message 3"
77
- # print "\rBig very very very very long message 4"
78
- # print "\rBig very very very very long message 7"
79
- # print "\rBig very very very very long message 8"
80
- # end
81
- # ].each(&:join)
82
- # end.join
@@ -1,23 +0,0 @@
1
- require_relative "../lib/fibril/loop"
2
-
3
- pending = promise{ sleep 1; 3 }
4
- pending2 = promise{ sleep 0.1; 4 }
5
-
6
- fibril{
7
- puts "First"
8
- puts async.await(pending)
9
- puts "First"
10
- }
11
-
12
- fibril{
13
- puts "Second"
14
- result = async.await_all pending, pending2
15
- puts "Second"
16
- puts "Result is #{result}"
17
- }
18
-
19
- fibril{
20
- puts "Third"
21
- puts async.await(pending2)
22
- puts "Third"
23
- }